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

Pass a better message back to JS #10

Merged
merged 5 commits into from
Jul 12, 2023
Merged

Pass a better message back to JS #10

merged 5 commits into from
Jul 12, 2023

Conversation

mansona
Copy link
Member

@mansona mansona commented Jul 7, 2023

fixes #1

@mansona mansona requested a review from a team July 7, 2023 17:11
@ef4
Copy link
Collaborator

ef4 commented Jul 8, 2023

Thanks.

Can we please try to match the output of the pure rust examples? For example, run cargo run ./sample/has_error.js and you'll see that it produces a codeframe pointing at the syntax error:

Screenshot 2023-07-08 at 3 56 55 PM

swc is already tracking squrcemap-like details that enable it to produce this output. If we can just capture those and attach them to the exception, we'd be able to match the pretty output even from JS.

@mansona
Copy link
Member Author

mansona commented Jul 11, 2023

So it turns out this was surprisingly difficult 🙈 I don't know if it's just a result of the API that SWC has for its errors but I had to do some Rust jujitsu that was a bit outside of my confort zone to get this to work 🙃

I "stole" the implementation of the "error to string" functionality from https://github.com/swc-project/swc/blob/e4f9f734ad1f92c6f05e8cb4c2d799679cca9f79/crates/swc_error_reporters/tests/fixture.rs so I hope it's ok.

Also worth noting that I wasn't able to match the CLI version output exactly no matter what I did 🤔 I tried different handlers with different GraphicalThemes but nothing seemed to work. I settled for one that was as close as I could get 👍

ef4 added 2 commits July 11, 2023 13:12
This is purely refactor, before I made other changes.
@ef4 ef4 merged commit 59ea115 into main Jul 12, 2023
@ef4 ef4 deleted the pass-message branch July 12, 2023 05:32
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.

Report errors through the WASM bindings
2 participants