-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Handle compiler errors in Rust. #2310
Conversation
This is a more complete PR, but still a bit of work to do, I just wanted to push an update. Now I also think they we should consider conforming all internal user facing logging to this format, which in theory would include stuff from Rust. The structure is pretty robust now, being able to handle complex sets of diagnostics as well as stacks of frames. |
Ok, it is functionally complete now, I think. I need to add some more tests in Rust and rebaseline the outputs of a lot of other error related tests. |
@ry I think this if finally ready for review... |
}) | ||
} | ||
|
||
pub fn from_json_value(v: serde_json::Value) -> Option<Self> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also should have a unit test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooops, I forgot to add this one, it isn't my code, it was from core/js_error.rs
originally and doesn't have a unit test there, as it is from the V8 error, but I will add one.
@kitsonk I suggest not making changes in |
Hmmm... I missed this comment. That would be undoing a fair amount of work and divergent from the conversations we had along the way, which was to merge JSError and the TS Diagnostics, which is what this PR does, using the same structure. I am going to finish off the other feedback and have rebase on the changes to compiler. I argue that it is overall cleaner that we have a single structure named |
@ry @bartlomieju I think I have addressed all feedback (plus rebased on the compiler changes). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Output looks good and (mostly) passing for me locally.
It's not clear to me why any changes need to be made to core? The core/js_errors.rs
module is nice because it's designed just to consume the JSON blob from V8, without further complicating things. It's nice to have that independence for testing and also for users who don't want TS. I think cli/diagnostics.rs
would just implement From<deno::JSError>
...
@ry Yeah. I see the problem. I still think there is value in there being a core diagnostic structure, versus an opinionated one that can be used for any "userland" errors, even using them when ops are bad in Rust land or there are bad arguments. I will try to separate out the logic for the TS diagnostics. Because clearly that should only exist in CLI. |
I have been thinking about this quite a bit. I think there is an argument for starting over with this and not trying to merge So I suspect I will close this and start a new branch PR that just focuses on adding the diagnostics to the compiler in CLI and doesn't touch core. |
@kitsonk consider using |
@bartlomieju it does and it doesn't... As far as the TypeScript diagnostics, there are some strange structures in there (like the message chain) which don't deserialise to Rust well that the procedural code around |
Closing in lieu of #2445. |
Resolves #1738
This has gotten to the point where it is ready for light review and feedback. Instead of the compiler outputting errors and exiting, it returns TypeScript errors to Rust which then will log them to the console and exit.
The biggest change on the Rust side is that
JSError
has been renamed toDenoDiagnostic
and both compiler errors and V8 errors are unified. It might make sense to also unify other errors/panics to this format over time, so we have a unified error structure.Things that still need to be done:
Tests
Handle multiple errors returning from the compiler for a given module, currently only the first error is output
Handle diagnostic changes, the TypeScript compiler can output a chain of errors which need to be formatted and displayed.
Enhance all outputs to be more aligned to the way TypeScript outputs errors:
Currently the output for an error looks like this:
Where we actually want it to look more like this:
If you want to see the branch in action, build it and then run something like: