-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: emit new Error(ID, {cause: CAML_EXN})
for exceptions
#1036
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Some questions for the parts i don't understand.
For both interop and performance reasons, wouldn't it be better to have a MelangeError class? Such that melange errors can be detected with Also is cause supported in older versions or it will be discarded? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause Anyway, the MelangeError class could support both |
It might be interesting to play with a |
@EduardoRFS Sorry, I don't understand what would be the upsides of this. In terms of performance, bundling size at least would get worse with
In terms of detection, isn't the |
@jchavarri I was not talking about bundle size, but even that should shrink, as the MelangeError instance is smaller. About detection, I was not talking about detecting it in Melange itself, but instead, detecting it outside of Melange. throw new Error("Assert_failure", {
cause: {
MEL_EXN_ID: "Assert_failure",
_1: [
"jscomp/test/fun_pattern_match.ml",
41,
9
]
}
});
throw new MelangeError("Assert_failure", [
"jscomp/test/fun_pattern_match.ml",
41,
9
]); |
Thanks for clarifying. The part that I was missing is that the object with |
@jchavarri the object may still be there, it can still be accessed on the instance, is just that it is defined only inside of the constructor. |
some of the upsides:
Improvements in bundling size might be a bit negligible IMO (check #1043 (comment)) and not the main motivator for this. |
Adapted from melange-re/melange#1036 Thanks @anmonteiro
* throw as instance of JS `new Error()` Adapted from melange-re/melange#1036 Thanks @anmonteiro * uncomment test * update output * update build * [skip ci]: update CHANGELOG.md
Summary
Converts Melange-generated error throwing code to always emit a JS
Error
instance.fixes #975
Details
Before:
After
new Error()
and adds the extension payload forcause
in the Error cause option..cause
in the error being caught bytry .. catch(error) { .. }
code