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

Allow throwing a SyntaxError #833

Closed
idan-at opened this issue Nov 4, 2021 · 6 comments
Closed

Allow throwing a SyntaxError #833

idan-at opened this issue Nov 4, 2021 · 6 comments

Comments

@idan-at
Copy link
Contributor

idan-at commented Nov 4, 2021

Hey,

Relatd to swc-project/swc#2650

I'd like to refine swc error handling and throw a SyntaxError instead of an Error.

I see here that some global JS errors are supported, but not SyntaxErrorr.

Any objections to support it?

If you're fine with adding it, I can contribute.

EDIT: I see napi doesn't have an API for that :( Any suggestions?

@Brooooooklyn
Copy link
Sponsor Member

The original Node-API doesn't expose ability to create SyntaxError: https://nodejs.org/api/n-api.html#napi_create_type_error

@idan-at
Copy link
Contributor Author

idan-at commented Nov 6, 2021

you're correct, I'm working on it :)

@Brooooooklyn
Copy link
Sponsor Member

See https://github.com/napi-rs/napi-rs/releases/tag/napi%401.7.8

There is a workaround for this scenario

@idan-at
Copy link
Contributor Author

idan-at commented Nov 7, 2021

thank you! now that I take a look better, seems like swc actually needs create_syntax_error (here).

do you think we need to add it in a similar way or wait for the napi PR to be merged & deployed?

@idan-at
Copy link
Contributor Author

idan-at commented Dec 1, 2021

@Brooooooklyn hey,

nodejs/node#40736 was merged and released in v17.2.0 (nodejs/node#40983).

I'd be happy to contribute to napi-rs with this new addition. Can you please guide me?

should I just add it here under the napi8 feature?

@Brooooooklyn
Copy link
Sponsor Member

should I just add it here under the napi8 feature?

And here https://github.com/napi-rs/napi-rs/blob/main/crates/napi/src/env.rs#L650

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

No branches or pull requests

2 participants