Skip to content
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

Throw Js Erros constructor EvalError, RangeError, etc #6931

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

aspeddro
Copy link
Contributor

@aspeddro aspeddro commented Aug 4, 2024

After #6611 was merged it is no longer possible to throw errors like EvalError. The throw statement now is thow new Error(exn).

Example: The Js.Exn.raiseEvalError function:

https://github.com/rescript-lang/rescript-compiler/blob/0b1443f967808a41c3ad309002eca964f0b6465f/jscomp/others/js_exn.res#L48

compile to:

https://github.com/rescript-lang/rescript-compiler/blob/0b1443f967808a41c3ad309002eca964f0b6465f/lib/es6/js_exn.js#L10-L14

This PR add a function throw:

let throw: exn => 'a = %raw("function (exn) {
  throw exn;
}")

Side question

Here a question arises whether we should support EvalError and others, or encourage ReScript exceptions. Recently documented the exceptions builtin (rescript-lang/rescript-lang.org#880)

My idea is to use ReScript exceptions and not bindings to Js Error (i.e @new external make: string => t = "Error"). We will still catch Js Errors

Related #6929

@DZakh
Copy link
Contributor

DZakh commented Aug 4, 2024

This change will break my libs and applications

@aspeddro
Copy link
Contributor Author

aspeddro commented Aug 4, 2024

Your libs use Js.Exn.{raiseEvalError,raiseRangeError} functions?

@aspeddro aspeddro changed the title Cleanup Js.Exn functions Throw Js Erros constructor EvalError, RangeError, etc Aug 4, 2024
@aspeddro aspeddro marked this pull request as ready for review August 4, 2024 18:40
@DZakh
Copy link
Contributor

DZakh commented Aug 4, 2024

Sorry, I've taken a look at your PR, and it indeed improves things compared to the current v12 alpha release. But it doesn't solve the root of the problem, and for example, the Js.Exn.raiseError still have a regressed behaviour compared to v11.

I'm working on the PR #6933, which should automatically fix the issue you're trying to solve in the PR. This is why I think it's not needed.

@aspeddro
Copy link
Contributor Author

aspeddro commented Aug 5, 2024

What is the regression compared to v11?

@DZakh
Copy link
Contributor

DZakh commented Aug 5, 2024

What is the regression compared to v11?

Previously it would throw a new Error with the message provided via the arguments. Now it throws new Error("Failure", ... where message is hidden in the cause.

The main usecase for the Js.Exn.raiseError was to throw an error with a readable error message, which would be displayed nicely in logs, but now it's hidden in the cause field

@DZakh
Copy link
Contributor

DZakh commented Aug 5, 2024

And if we are talking about the issue #6929
Your PR will fix the case with Js.Exn.raiseError, but for the following code it still won't work: https://rescript-lang.org/try?version=v12.0.0-alpha.1&code=C4JwngBA3gUBEFIQEMDuAKABu9BKAvAHxTAAWIA9qhAK4B2AJgKYBmAlnUwwL656a4Y3CAGNkwEaWgwAPhCYAPOhCIQUbAM5N0iuoO4wgA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants