לוגי שגיאה בnodejs וyemotrouter מה הגורם לקריסה?
-
יש כאן כמה לוגים של שגיאה, רק אחד מהם גרם לקריסה ממש, אשמח לדעת מה גרם לקריסה, ומה הוא שונה מהשאר. לכאורה הם בערך אותם שגיאות.
[31m[541eba6e6682e37cee0ae3e53f2d794defc28d29]:
Uncaught error. applying uncaughtErrorHandler (node:internal/errors:405:5)[39m
Uncaught error in / from 0548497730. error stack: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:405:5)
at ServerResponse.setHeader (node:_http_outgoing:655:11)
at ServerResponse.header (/home/node.stamandsefer.co.il/public_html/node_modules/express/lib/response.js:684:10)
at ServerResponse.send (/home/node.stamandsefer.co.il/public_html/node_modules/express/lib/response.js:161:12)
at Call.send (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:264:18)
at sendResp (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:170:18)
at Call.read (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:179:15)
at choosestreet (file:///home/node.stamandsefer.co.il/public_html/src/utils/utils_func.js:141:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async callHandler (file:///home/node.stamandsefer.co.il/public_html/src/controllers/addAdController.js:60:22)
[31m[541eba6e6682e37cee0ae3e53f2d794defc28d29]: Cannot send id_list_message after sending response (probably done from uncaughtErrorHandler due to error in asynchronous code[31m[a7d099fc6c8dea530efaabba6c1b4ceb5476adb8]:
Uncaught error. applying uncaughtErrorHandler (node:internal/errors:405:5)[39m
Uncaught error in / from 0548497730. error stack: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:405:5)
at ServerResponse.setHeader (node:_http_outgoing:655:11)
at ServerResponse.header (/home/node.stamandsefer.co.il/public_html/node_modules/express/lib/response.js:684:10)
at ServerResponse.send (/home/node.stamandsefer.co.il/public_html/node_modules/express/lib/response.js:161:12)
at Call.send (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:264:18)
at sendResp (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:170:18)
at Call.read (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:179:15)
at choosestreet (file:///home/node.stamandsefer.co.il/public_html/src/utils/utils_func.js:141:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async callHandler (file:///home/node.stamandsefer.co.il/public_html/src/controllers/addAdController.js:60:22)
[31m[a7d099fc6c8dea530efaabba6c1b4ceb5476adb8]: Cannot send id_list_message after sending response (probably done from uncaughtErrorHandler due to error in asynchronous code[31m[b142a8637dd7dced030099e0f6655a63da484e0b]:
Uncaught error. applying uncaughtErrorHandler (node:internal/errors:405:5)[39m
Uncaught error in / from 0583297790. error stack: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:405:5)
at ServerResponse.setHeader (node:_http_outgoing:655:11)
at ServerResponse.header (/home/node.stamandsefer.co.il/public_html/node_modules/express/lib/response.js:684:10)
at ServerResponse.send (/home/node.stamandsefer.co.il/public_html/node_modules/express/lib/response.js:161:12)
at Call.send (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:264:18)
at sendResp (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:170:18)
at Call.read (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:179:15)
at choosestreet (file:///home/node.stamandsefer.co.il/public_html/src/utils/utils_func.js:141:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async callHandler (file:///home/node.stamandsefer.co.il/public_html/src/controllers/addAdController.js:60:22)
[31m[b142a8637dd7dced030099e0f6655a63da484e0b]: Cannot send id_list_message after sending response (probably done from uncaughtErrorHandler due to error in asynchronous code after returning response)[39m
Node starting...
app.js running on port 3000export async function choosestreet(call, city) { let menuStreet = "", digitsStreet=[], street; let okStreet = "0"; while(okStreet!="1") { let ans = await call.read([{ type: 'file', data: "/ivr_records/רחוב1" }], "record"); console.log(ans); try{ const keywords = JSON.stringify(streets[city]); street = await reco(call, ans,keywords, city); if (street==null) {continue;} } catch (error) { console.error("Error:", error); call.id_list_message([{ type: 'text', data: "אירעה שגיאה" }]); } { // מבקש אישור okStreet = await call.read([{ type: 'file' , data: `/ivr_records/${street}` },{ type: 'file' , data: "/ivr_records/אישור2" }], 'tap', { sec_wait: 2, min_digits: 1, typing_playback_mode: "No", digits_allowed: [1,2, "*0"] }); if (okStreet=="1") {return street;} else if (okStreet == "*0") {call.go_to_folder(mainextPath);} } }async function reco(call, ans, keywords,city) { try{ const { stdout, stderr } = await execFileAsync("python3", [ "/recognizeNew.py", ans,keywords]); const matches = JSON.parse(stdout); console.log(matches); if (stderr) { console.error("Python stderr:", stderr); } if (matches.length==0) { const { stdout, stderr } = await execFileAsync("python3", [ "recognize.py", ans,keywords]); if (stderr) { console.error("Python stderr:", stderr); } let recognizedText = stdout.trim(); // הסר רווחים ושורות מיותרות if(streets[city].includes(recognizedText)) { return recognizedText; } else {call.id_list_message([/*{type: 'text', data: "לא זיהינו את הרחוב שהקלטת"}*/{ type: 'file', data: "/ivr_records/שגיאה זיהוי" }],{prependToNextAction: true});} } else if (matches[0].score == 100) {return matches[0].name;} else { let msgmatches = [], digitsmatches=[]; for (let i = 0; i < matches.length; i++) { msgmatches.push({ type: 'file', data: `/ivr_records/${matches[i].name}` }); msgmatches.push({ type: 'file', data: `/ivr_records/הקש` }); msgmatches.push(...Object.values(numberToHebrewWords(i+1))); digitsmatches.push((i + 1).toString()); } digitsmatches.push("*0"); let street; for(let i = 0; i<3; i++) { street = await call.read(msgmatches, 'tap', { max_digits: 2, sec_wait: 2, min_digits: 1, digits_allowed: digitsmatches, typing_playback_mode: "No" }); if (street == "*0") {call.go_to_folder(mainextPath);} if (!digitsmatches.includes(street)) { continue; // אם הקיש מספר לא חוקי – חוזר על הלולאה } const index = Number(street) - 1; if (index >= matches.length) { continue; // אם הקיש מספר לא חוקי – חוזר על הלולאה } street = matches[index].name; return street; } call.hangup(); } } catch (error) { console.error("Error:", error); call.id_list_message([{ type: 'text', data: "אירעה שגיאה" }]); } } -
יש כאן כמה לוגים של שגיאה, רק אחד מהם גרם לקריסה ממש, אשמח לדעת מה גרם לקריסה, ומה הוא שונה מהשאר. לכאורה הם בערך אותם שגיאות.
[31m[541eba6e6682e37cee0ae3e53f2d794defc28d29]:
Uncaught error. applying uncaughtErrorHandler (node:internal/errors:405:5)[39m
Uncaught error in / from 0548497730. error stack: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:405:5)
at ServerResponse.setHeader (node:_http_outgoing:655:11)
at ServerResponse.header (/home/node.stamandsefer.co.il/public_html/node_modules/express/lib/response.js:684:10)
at ServerResponse.send (/home/node.stamandsefer.co.il/public_html/node_modules/express/lib/response.js:161:12)
at Call.send (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:264:18)
at sendResp (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:170:18)
at Call.read (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:179:15)
at choosestreet (file:///home/node.stamandsefer.co.il/public_html/src/utils/utils_func.js:141:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async callHandler (file:///home/node.stamandsefer.co.il/public_html/src/controllers/addAdController.js:60:22)
[31m[541eba6e6682e37cee0ae3e53f2d794defc28d29]: Cannot send id_list_message after sending response (probably done from uncaughtErrorHandler due to error in asynchronous code[31m[a7d099fc6c8dea530efaabba6c1b4ceb5476adb8]:
Uncaught error. applying uncaughtErrorHandler (node:internal/errors:405:5)[39m
Uncaught error in / from 0548497730. error stack: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:405:5)
at ServerResponse.setHeader (node:_http_outgoing:655:11)
at ServerResponse.header (/home/node.stamandsefer.co.il/public_html/node_modules/express/lib/response.js:684:10)
at ServerResponse.send (/home/node.stamandsefer.co.il/public_html/node_modules/express/lib/response.js:161:12)
at Call.send (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:264:18)
at sendResp (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:170:18)
at Call.read (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:179:15)
at choosestreet (file:///home/node.stamandsefer.co.il/public_html/src/utils/utils_func.js:141:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async callHandler (file:///home/node.stamandsefer.co.il/public_html/src/controllers/addAdController.js:60:22)
[31m[a7d099fc6c8dea530efaabba6c1b4ceb5476adb8]: Cannot send id_list_message after sending response (probably done from uncaughtErrorHandler due to error in asynchronous code[31m[b142a8637dd7dced030099e0f6655a63da484e0b]:
Uncaught error. applying uncaughtErrorHandler (node:internal/errors:405:5)[39m
Uncaught error in / from 0583297790. error stack: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:405:5)
at ServerResponse.setHeader (node:_http_outgoing:655:11)
at ServerResponse.header (/home/node.stamandsefer.co.il/public_html/node_modules/express/lib/response.js:684:10)
at ServerResponse.send (/home/node.stamandsefer.co.il/public_html/node_modules/express/lib/response.js:161:12)
at Call.send (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:264:18)
at sendResp (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:170:18)
at Call.read (file:///home/node.stamandsefer.co.il/public_html/node_modules/yemot-router2/lib/call.js:179:15)
at choosestreet (file:///home/node.stamandsefer.co.il/public_html/src/utils/utils_func.js:141:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async callHandler (file:///home/node.stamandsefer.co.il/public_html/src/controllers/addAdController.js:60:22)
[31m[b142a8637dd7dced030099e0f6655a63da484e0b]: Cannot send id_list_message after sending response (probably done from uncaughtErrorHandler due to error in asynchronous code after returning response)[39m
Node starting...
app.js running on port 3000export async function choosestreet(call, city) { let menuStreet = "", digitsStreet=[], street; let okStreet = "0"; while(okStreet!="1") { let ans = await call.read([{ type: 'file', data: "/ivr_records/רחוב1" }], "record"); console.log(ans); try{ const keywords = JSON.stringify(streets[city]); street = await reco(call, ans,keywords, city); if (street==null) {continue;} } catch (error) { console.error("Error:", error); call.id_list_message([{ type: 'text', data: "אירעה שגיאה" }]); } { // מבקש אישור okStreet = await call.read([{ type: 'file' , data: `/ivr_records/${street}` },{ type: 'file' , data: "/ivr_records/אישור2" }], 'tap', { sec_wait: 2, min_digits: 1, typing_playback_mode: "No", digits_allowed: [1,2, "*0"] }); if (okStreet=="1") {return street;} else if (okStreet == "*0") {call.go_to_folder(mainextPath);} } }async function reco(call, ans, keywords,city) { try{ const { stdout, stderr } = await execFileAsync("python3", [ "/recognizeNew.py", ans,keywords]); const matches = JSON.parse(stdout); console.log(matches); if (stderr) { console.error("Python stderr:", stderr); } if (matches.length==0) { const { stdout, stderr } = await execFileAsync("python3", [ "recognize.py", ans,keywords]); if (stderr) { console.error("Python stderr:", stderr); } let recognizedText = stdout.trim(); // הסר רווחים ושורות מיותרות if(streets[city].includes(recognizedText)) { return recognizedText; } else {call.id_list_message([/*{type: 'text', data: "לא זיהינו את הרחוב שהקלטת"}*/{ type: 'file', data: "/ivr_records/שגיאה זיהוי" }],{prependToNextAction: true});} } else if (matches[0].score == 100) {return matches[0].name;} else { let msgmatches = [], digitsmatches=[]; for (let i = 0; i < matches.length; i++) { msgmatches.push({ type: 'file', data: `/ivr_records/${matches[i].name}` }); msgmatches.push({ type: 'file', data: `/ivr_records/הקש` }); msgmatches.push(...Object.values(numberToHebrewWords(i+1))); digitsmatches.push((i + 1).toString()); } digitsmatches.push("*0"); let street; for(let i = 0; i<3; i++) { street = await call.read(msgmatches, 'tap', { max_digits: 2, sec_wait: 2, min_digits: 1, digits_allowed: digitsmatches, typing_playback_mode: "No" }); if (street == "*0") {call.go_to_folder(mainextPath);} if (!digitsmatches.includes(street)) { continue; // אם הקיש מספר לא חוקי – חוזר על הלולאה } const index = Number(street) - 1; if (index >= matches.length) { continue; // אם הקיש מספר לא חוקי – חוזר על הלולאה } street = matches[index].name; return street; } call.hangup(); } } catch (error) { console.error("Error:", error); call.id_list_message([{ type: 'text', data: "אירעה שגיאה" }]); } } -
@eido יש רק שלוש דרכים לעצור קוד שרץ באמצע פונקציה בלי משפטי בקרה (if/for/break וכדומה):
return
throw
await.
בפונקציה choosestreet אתה קורא לid_list_message בתוך לולאה ובלי await.
מהקוד הזה שלא מסודר מבחינת ההזחות יחד עם העובדה שיש שמה סוגריים מסולסלות מיותרות, אני לומד שאתה עובד קשה לכתוב קוד בלי IDE או ידע בסיסי בעניין. כדאי לך להשלים את החסרים האלה, זה יוריד ממך הרבה הרבה טרחה ותלמד הרבה יותר מהר להבין את הקוד. -
@eido כי יש כמה פעמים שאתה מחזיר משהו אבל אתה לא עוצר את הקוד, כך שהקוד ממשיך לרוץ ומחזיר כמה דברים ביחד, וזה מה שגורם לשגיאות כאלה
@ששא כתב בלוגי שגיאה בnodejs וyemotrouter מה הגורם לקריסה?:
@eido כי יש כמה פעמים שאתה מחזיר משהו אבל אתה לא עוצר את הקוד, כך שהקוד ממשיך לרוץ ומחזיר כמה דברים ביחד, וזה מה שגורם לשגיאות כאלה
אדייק, בעיקרון הספריה עצמה מונעת מקרים כאלה על ידי זריקת שגיאה מלאכותית של
ExitErrorאחרי פעולות שמחזירות למשתמש סטרינג שאמור להוציא אותו מהשלוחה
הבעיה היא ש @eido עושה try catch ענקיים בלי סיבה, וגם לא בודק את השגיאה