-
Is there a way to get some information (error, line number) when JS runtime error happens when running in instrumented build? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Some information? Yes. An instrumented build is a release build, so not all debugging information is available. For example, the source code file names and line numbers are removed from the byte code. But, the function names are still available. When an unhanded exception occurs, XS calls #if defined(mxDebug) && !MODDEF_XS_TEST
if ((char *)&the <= the->stackLimit)
the->stackLimit = NULL;
fxDebugger(the, (char *)__FILE__, __LINE__);
#elif defined(mxInstrument) && !defined(mxDebug)
if (XS_STACK_OVERFLOW_EXIT != status) {
mxPush(mxException);
txSlot *exception = the->stack;
mxException = xsUndefined;
mxTry(the) {
mxOverflow(-8);
mxPush(mxGlobal);
fxCallID(the, fxFindName(the, "abort"));
mxPushStringC((char *)msg);
mxPushSlot(exception);
fxRunCount(the, 2);
mxPop();
}
mxCatch(the) {
}
}
#endif Notice that it does not call the JavaScript abort handler in the case of a stack overflow, as it would immediately fail. It does call it on memory failures. It may fail too, but depending on the runtime situation it might succeed too. Here's a small test app: globalThis.abort = function (msg, exception) {
trace(msg, ":\n", exception.stack, "\n");
}
function foo() {
throw new Error("forced error");
}
function boo() {
foo();
}
function test() {
boo();
}
trace("running\n");
test(); Here's the output:
If this is useful, we can look into integrating it as an option into the hosts. |
Beta Was this translation helpful? Give feedback.
-
I tested the code and it works! I think this is a necessary feature, and I don't like the default behavior. |
Beta Was this translation helpful? Give feedback.
-
@phoddie A follow up question here: |
Beta Was this translation helpful? Give feedback.
Some information? Yes.
An instrumented build is a release build, so not all debugging information is available. For example, the source code file names and line numbers are removed from the byte code. But, the function names are still available.
When an unhanded exception occurs, XS calls
fxAbort
in the host. The behavior from there is determined by the host. By default, we restart. This is safest behavior (Node strongly agrees). But, other behaviors are possible. For example, we can call a JavaScript function to display the stack and perhaps other information. To try that, you can modify this section of fxAbort in the ESP host to call a globalabort
function: