Hi all, the current exception is encoded using an object literal attached with an error, e.g
Take Assert_false
for example, it is encoded as below:
{
RE_EXN_ID: "Assert_failure",
_1: [
"tscanf_test.ml",
174,
2
],
Error: new Error()
};
This works great when such exception is uncaught, the stacktrace is printed properly.
However, when such exception is caught by third party APIs, for example, mocha or bugsnag, they try to catch the exception and extract stack
property which does not exist in our exception object. Therefore, such 3rd party tools will not report stacktrace properly.
I am proposing to change such exception encoding to make it work better with 3rd party tools:
Proposal 1
{
RE_EXN_ID: "Assert_failure",
_1: [
"tscanf_test.ml",
174,
2
],
stack: (new Error()).stack
};
Proposal 2
Object.assign(new Error, {RE_EXN_ID: "Assert_failure",
_1: [
"tscanf_test.ml",
174,
2
]
})
Pros for Proposal 1
- Easy to implement
- Matches better with existing semantics
- Payload is also displayed properly (_1 field)
Cons for Proposal 1
- unclear
stack
alone would work better enough with existing tools
Pros for Proposal 2
- Perfect integration with js toolset
Cons for Proposal 2
- Payload not displayed properly (need more tweaks)
- Semantics more deviation from existing encoding
- More complexity (may need a small runtime)
I tend to implement proposal 1 due to its simplicity, but would like to know if I miss some obvious downside of proposal 1
cc @BlueHotDog