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

Add throw #7346

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

Add throw #7346

wants to merge 8 commits into from

Conversation

aspeddro
Copy link
Contributor

Deprecate raise and rename references.

Close #7113

Deprecate `raise` and rename references
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add @@deprecated to this module?

It has the same content as https://github.com/rescript-lang/rescript/blob/master/runtime/Stdlib_Error.res

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't have exactly the same content though, Error is missing the definition of a JS exception that today is catched with Exn.Error(obj), but I agree the current situation is not ideal, maybe we could merge the two?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will explore this in another PR

Copy link
Contributor

@tsnobip tsnobip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for doing this @aspeddro, I think that's a nice improvement. I'm just not sure if we should also deprecate raise, having both without any explanation feels a bit weird to me. I'm also not sure about what we should do for Stdlib.Exn module, but I'd advise to keep this work for another PR to avoid bikeshedding on this topic.

@@ -1,5 +1,6 @@
/* Exceptions */
external raise: exn => 'a = "%raise"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we deprecate raise or keep both for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@aspeddro
Copy link
Contributor Author

We can add to deprecated attribute?

raise has been renamed to throw to align with JavaScript vocabulary. Please use throw.

@@ -100,6 +100,7 @@ async function main() {
external import: 'a => promise<'a> = "%import"

let panic = Error.panic
let throw = Error.throw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not zero-cost (causes a $$throw function to be emitted in Stdlib.js). I am afraid we need to repeat the external definition here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
```
*/
external throw: Error.t => 'a = "%raise"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add the external here or just leave it in the Stdlib_Error.res module?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe clearer to add it in Pervasives on top of the deprecated raise instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@aspeddro
Copy link
Contributor Author

CHANGELOG updated

@aspeddro aspeddro requested a review from cknitt March 20, 2025 19:16
@cknitt
Copy link
Member

cknitt commented Mar 21, 2025

@aspeddro did you see my comment?

Should I add the external here or just leave it in the Stdlib_Error.res module?

Maybe clearer to add it in Pervasives on top of the deprecated raise instead?

@aspeddro
Copy link
Contributor Author

@aspeddro did you see my comment?

Should I add the external here or just leave it in the Stdlib_Error.res module?

Maybe clearer to add it in Pervasives on top of the deprecated raise instead?

Yes, I will adjust

@fhammerschmidt
Copy link
Member

Should we also have a throws decorator as an alias to raises in reanalyze?

@cristianoc
Copy link
Collaborator

Should we also have a throws decorator as an alias to raises in reanalyze?

Good idea.

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.

raise -> throw
5 participants