Spaces:
Running
Running
fix: prevent infinite recursion in passage extraction
Browse files- Replace recursive call with fallback approach when passage too short
- Use simple sentence detection as emergency fallback
- Prevents 'too much recursion' error that crashes game loading
- src/clozeGameEngine.js +11 -3
src/clozeGameEngine.js
CHANGED
@@ -97,10 +97,18 @@ class ClozeGame {
|
|
97 |
passage = sentences.join(' ');
|
98 |
}
|
99 |
|
100 |
-
// Ensure minimum length
|
101 |
if (passage.length < 400) {
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
|
106 |
return passage.trim();
|
|
|
97 |
passage = sentences.join(' ');
|
98 |
}
|
99 |
|
100 |
+
// Ensure minimum length - if too short, return what we have rather than infinite recursion
|
101 |
if (passage.length < 400) {
|
102 |
+
console.warn('Short passage extracted, using fallback approach');
|
103 |
+
// Try one more time with a simpler approach
|
104 |
+
const simpleStart = text.indexOf('. ') + 2;
|
105 |
+
if (simpleStart > 1 && simpleStart < text.length - 500) {
|
106 |
+
passage = text.substring(simpleStart, simpleStart + 600);
|
107 |
+
const lastPeriod = passage.lastIndexOf('.');
|
108 |
+
if (lastPeriod > 200) {
|
109 |
+
passage = passage.substring(0, lastPeriod + 1);
|
110 |
+
}
|
111 |
+
}
|
112 |
}
|
113 |
|
114 |
return passage.trim();
|