-
Let's say we have an exception: const testJsErrorFromJsCode = () => {
DBG('=== testJsErrorFromJsCode ===')
throw new Error('Test JS error from JS code')
} And I'm getting this from console log:
And I found in Line 1382 in 0135c0e I found the messages are hardcoded as "throw". Is there a reason why we cannot extract the message from Exception object from here? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
There are reasons. First, there is no guarantee that the throw is an instance of throw 1;
throw undefined;
throw Promise.resolve(); Additionally, it is possible that naively attempting to get the class AnError extends Error {
set message(m) {
}
get message() {
throw new Error("boom");
}
}
throw new AnError("yikes"); So, XS is conservative here to avoid having the debugger introduce unexpected behaviors. To do what you suggest should be possible by first checking that exception is an Error instance and then accessing the |
Beta Was this translation helpful? Give feedback.
-
The information above is correct, but incomplete. When running with the debugger, XS logs what you want: You must either be running a debug build without the debugger or an instrumented build. Those paths don't log the details. Maybe you can explain a bit more about your environment? FWIW – another approach is to log the exception yourself. If you are only interested in unhandled exceptions (which reset by default), you can enable the abort hook (MODDEF_XS_ABORTHOOK) which calls |
Beta Was this translation helpful? Give feedback.
-
OK, As I suspected, it was my "main.c"'s problem ... This is the original structure of my main.c int main(int argc, char *argv[]) {
// ... Prepare work
txMachine *the = &_root;
// ... More code
the = fxCloneMachine(&preparation->creation, the, "linemb", NULL);
xsBeginHost(the);
{
xsTry
{
xsResult = xsAwaitImport("main", XS_IMPORT_NAMESPACE);
}
xsCatch
{
xsStringValue message = xsToString(xsException);
fprintf(stderr, "### %s\n", message);
error = 1;
}
// Start event loop
GMainContext *main_context = g_main_context_default();
GMainLoop *main_loop = g_main_loop_new(main_context, FALSE);
g_main_loop_run(main_loop);
// End event loop
}
xsEndHost(the);
xsDeleteMachine(the);
return error;
} As we can see, I wrapped the main loop inside Now I fixed it as following:
int main(int argc, char *argv[]) {
// ... Prepare work
txMachine *the = &_root;
// ... More code
the = fxCloneMachine(&preparation->creation, the, "linemb", NULL);
xsBeginHost(the);
{
// xsTry
// {
xsResult = xsAwaitImport("main", XS_IMPORT_NAMESPACE);
// }
// xsCatch
// {
// xsStringValue message = xsToString(xsException);
// fprintf(stderr, "### %s\n", message);
// error = 1;
// }
}
xsEndHost(the);
// Start event loop
GMainContext *main_context = g_main_context_default();
GMainLoop *main_loop = g_main_loop_new(main_context, FALSE);
g_main_loop_run(main_loop);
// End event loop
xsDeleteMachine(the);
return error;
} After this, all cases (including the unhandled rejection) correctly trigger the abortHook. I guess few people will facing this issue... I spent most of the time trying to understand how How |
Beta Was this translation helpful? Give feedback.
OK, As I suspected, it was my "main.c"'s problem ...
This is the original structure of my main.c