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

fix(core) Include causes when converting anyhow errors to JS exceptions #16397

Merged
merged 6 commits into from
Oct 26, 2022
Merged

fix(core) Include causes when converting anyhow errors to JS exceptions #16397

merged 6 commits into from
Oct 26, 2022

Conversation

honzasp
Copy link
Contributor

@honzasp honzasp commented Oct 24, 2022

When an op returns an anyhow error with a cause (usually added using the .context() method), the Error thrown into JavaScript contains only the message of the outernmost error in the chain.

This PR simply changes the formatting of anyhow::Error from "{}" to "{:#}":

https://docs.rs/anyhow/latest/anyhow/struct.Error.html#display-representations

This significantly improves errors for code that embeds Deno and defines custom ops. For example, in chiselstrike/chiselstrike, this PR improves an error message like

Error: could not plan migration

to

Error: could not plan migration: could not migrate table for entity "E": could not add column for field "title": the field does not have a default value

@CLAassistant
Copy link

CLAassistant commented Oct 24, 2022

CLA assistant check
All committers have signed the CLA.

@bartlomieju
Copy link
Member

Thanks @honzasp, any chance you could add some test case so we don't accidently regress in the future?

@honzasp
Copy link
Contributor Author

honzasp commented Oct 26, 2022

I added a test to core/runtime.rs; I tried to make it similar to the other tests in that file, but I'm happy to rework it if necessary :)

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @honzasp!

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.

3 participants