You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tweak exception to work better with js toolchain #4898
This gives us good stacktrace when it is uncaught, but it does not work well with existing js toolchains. For example, mocha will catch such exception, and check the stack property which does not exist (we hit similar internal issues before). I am proposing to tweak it to the below one:
throw(Object.assign(newError,{RE_EXN_ID: "Assert_failure",// needed for internal markermessage : "Assert_failure",// to make default printing idiomatic_1: ["tscanf_test.ml",174,2]})
This data representation should work better with existing js toolset.
TODO: make sure nullary exception, e.g, Not_found work as expected.
Cons: it seems the payload _1 not printed by default in this case
Reacted by Roma P., Yawar Amin and Daniel Rodríguez Rivero
This is extremely important for real world usage scenarios. As much as I love rescript type system, errors will happen, and exceptions will be thrown. Making custom exceptions play well with the host language and its tooling is critical to build applications. Lost of tools rely on the (bad) habit of communication by throwing exceptions, and proper exception shape is critical.
By the way, why not just extend the error class as has been suggested on the linked issue?
Activity
[-]Tweak exception objects[/-][+]Tweak exception to work better with js toolchain[/+]bobzhang commentedon Jan 4, 2021
related to #4506
bobzhang commentedon Jan 14, 2021
For the record, such encoding seems to strike a good balance:
danielo515 commentedon Nov 26, 2022
This is extremely important for real world usage scenarios. As much as I love rescript type system, errors will happen, and exceptions will be thrown. Making custom exceptions play well with the host language and its tooling is critical to build applications. Lost of tools rely on the (bad) habit of communication by throwing exceptions, and proper exception shape is critical.
By the way, why not just extend the error class as has been suggested on the linked issue?
fhammerschmidt commentedon May 31, 2024
This has finally been implemented in #6611