-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
enhance(errors): Integrate miette for enhanced diagnostic reporting #10241
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
enhance(errors): Integrate miette for enhanced diagnostic reporting #10241
Conversation
🦋 Changeset detectedLatest commit: 0d98cd8 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
CodSpeed Performance ReportMerging #10241 will degrade performances by 1.71%Comparing Summary
Benchmarks breakdown
|
f9f2397 to
d27e639
Compare
|
Actually, a breaking change is fine until next version of |
Got,I will update code later. |
a2bebf7 to
c962f90
Compare
21b984d to
7ec66ba
Compare
7ec66ba to
15292bb
Compare
kdy1
left a comment
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.
Btw, I love this PR :)
0400dc0 to
ba67496
Compare
- Added `miette` as a dependency for improved error handling and reporting. - Updated diagnostic handling to utilize `miette` for pretty printing errors. - Introduced a new `DiagnosticCollection` to manage and store diagnostics. - Refactored emitters to support the new diagnostic structure and ensure compatibility with `miette`. - Enhanced error handling in various components to provide clearer and more informative error messages.
- Removed the `to_pretty_string` function and related error handling logic from various files to streamline error reporting. - Replaced `DiagnosticCollection` with `DiagnosticWriter` for better management of diagnostics. - Updated error handling in `swc_error_reporters` to utilize the new structure. - Deleted the unused `json_emitter` module to clean up the codebase. - Enhanced the `BufferedEmitter` for improved diagnostic output in testing scenarios.
6cd8b72 to
923a434
Compare
…`In practice this would nearly always result in OpenSSL treating the properties as an empty string`
kdy1
left a comment
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.
Thank you so much!
…10241) # Description SWC api `try_with_handler` only return anyhow!(msg) Err, it'a will lose many message about error stack, level ..., To express more error message in swc, we can return `Vec<Diagnostic>` in `try_with_handler`; try_with_handler_diagnostic return a `Result<Ret, Vec<Diagnostic>>`. Later user can using `diagnostic.code` to distinguish what kind error is. - Added `miette` as a dependency for improved error handling and reporting. - Updated diagnostic handling to utilize `miette` for pretty printing errors. - Introduced a new `ThreadSafetyDiagnostics` to manage and store diagnostics. - Refactored emitters to support the new diagnostic structure and ensure compatibility with `miette`. - Enhanced error handling in various components to provide clearer and more informative error messages. # BREAKING CHANGE: The api `try_with_handler` would not return anyhow!(msg). It's will return WrapperDiagnostics as it's Err. Then you can take diagnostics from WrapperDiagnostics or get pretty string from it. ```diff - pub fn try_with_handler<F, Ret>(cm: Lrc<SourceMap>, config: HandlerOpts, op:F) -> Result<Ret, anyhow::error>; + pub fn try_with_handler<F, Ret>(cm: Lrc<SourceMap>, config: HandlerOpts, op:F) -> Result<Ret, WrapperDiagnostics>; ``` ```rust /// A wrapper around a value that also contains a list of diagnostics. /// It helps swc error system migrate to the new error reporting system. pub struct WrapperDiagnostics { diagnostics: Vec<SwcDignostic>, .... } impl WrapperDiagnostics { pub fn diagnostics(&self) -> &[Diagnostic] { &self.diagnostics } pub fn to_pretty_error(&self) -> anyhow::Error { let error_msg = self.to_pretty_string(); anyhow::anyhow!(error_msg) } pub fn to_pretty_string(&self) -> String { .... } } ``` ### formatting In SWC, the `Syntax Error` message formatting dependents anyhow. ```rust // input: Foo {} // https://play.swc.rs/?version=1.11.13&code=H4sIAAAAAAAAA3PLz1eorgUAR6TWygYAAAA%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BAWdSIifrKJVBTl7iUE0maH3xsz8jooBbNoeKq1PMsQkYX4nEsi2Sf8lARIOxTNJia49XaWvRrRCtVoOxpIyBOluiX3hoMNQajjLXPGmzH%2FC3VwkUnkCu4o%2BsnSVTc0JbjwXmrZDkk50qF%2FwA%2FqsvNjMPLqm4kXGrYvhlQioBQBAAA%3D x Expected ';', '}' or <eof> ,-[input.js:1:1] 1 | Foo {} : ^|^ ^ : `-- This is the expression part of an expression statement `---- Caused by: 0: failed to process js file 1: Syntax Error ``` So if we return `Vec<Diagnostic>` instead of `anyhow:Error`, The output formatting would have a litter breaking change. ```diff x Expected ';', '}' or <eof> ,-[input.js:1:1] 1 | Foo {} : ^|^ ^ : `-- This is the expression part of an expression statement `---- - Caused by: - 0: failed to process js file - 1: Syntax Error + x Syntax Error ``` # Related issue: - Closes #10192 --------- Co-authored-by: Donny/강동윤 <[email protected]>
…10241) # Description SWC api `try_with_handler` only return anyhow!(msg) Err, it'a will lose many message about error stack, level ..., To express more error message in swc, we can return `Vec<Diagnostic>` in `try_with_handler`; try_with_handler_diagnostic return a `Result<Ret, Vec<Diagnostic>>`. Later user can using `diagnostic.code` to distinguish what kind error is. - Added `miette` as a dependency for improved error handling and reporting. - Updated diagnostic handling to utilize `miette` for pretty printing errors. - Introduced a new `ThreadSafetyDiagnostics` to manage and store diagnostics. - Refactored emitters to support the new diagnostic structure and ensure compatibility with `miette`. - Enhanced error handling in various components to provide clearer and more informative error messages. # BREAKING CHANGE: The api `try_with_handler` would not return anyhow!(msg). It's will return WrapperDiagnostics as it's Err. Then you can take diagnostics from WrapperDiagnostics or get pretty string from it. ```diff - pub fn try_with_handler<F, Ret>(cm: Lrc<SourceMap>, config: HandlerOpts, op:F) -> Result<Ret, anyhow::error>; + pub fn try_with_handler<F, Ret>(cm: Lrc<SourceMap>, config: HandlerOpts, op:F) -> Result<Ret, WrapperDiagnostics>; ``` ```rust /// A wrapper around a value that also contains a list of diagnostics. /// It helps swc error system migrate to the new error reporting system. pub struct WrapperDiagnostics { diagnostics: Vec<SwcDignostic>, .... } impl WrapperDiagnostics { pub fn diagnostics(&self) -> &[Diagnostic] { &self.diagnostics } pub fn to_pretty_error(&self) -> anyhow::Error { let error_msg = self.to_pretty_string(); anyhow::anyhow!(error_msg) } pub fn to_pretty_string(&self) -> String { .... } } ``` ### formatting In SWC, the `Syntax Error` message formatting dependents anyhow. ```rust // input: Foo {} // https://play.swc.rs/?version=1.11.13&code=H4sIAAAAAAAAA3PLz1eorgUAR6TWygYAAAA%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BAWdSIifrKJVBTl7iUE0maH3xsz8jooBbNoeKq1PMsQkYX4nEsi2Sf8lARIOxTNJia49XaWvRrRCtVoOxpIyBOluiX3hoMNQajjLXPGmzH%2FC3VwkUnkCu4o%2BsnSVTc0JbjwXmrZDkk50qF%2FwA%2FqsvNjMPLqm4kXGrYvhlQioBQBAAA%3D x Expected ';', '}' or <eof> ,-[input.js:1:1] 1 | Foo {} : ^|^ ^ : `-- This is the expression part of an expression statement `---- Caused by: 0: failed to process js file 1: Syntax Error ``` So if we return `Vec<Diagnostic>` instead of `anyhow:Error`, The output formatting would have a litter breaking change. ```diff x Expected ';', '}' or <eof> ,-[input.js:1:1] 1 | Foo {} : ^|^ ^ : `-- This is the expression part of an expression statement `---- - Caused by: - 0: failed to process js file - 1: Syntax Error + x Syntax Error ``` # Related issue: - Closes #10192 --------- Co-authored-by: Donny/강동윤 <[email protected]>
## Summary <!-- Can you explain the reasoning behind implementing this change? What problem or issue does this pull request resolve? --> See: - Rspack: web-infra-dev/rspack#10256 - Breaking changes: - `source_map_url`: swc-project/swc#10346 - `&mut DiagnosticBuilder<'_>`: swc-project/swc#10241 <!-- It would be helpful if you could provide any relevant context, such as GitHub issues or related discussions. --> ## Checklist <!--- Check and mark with an "x" --> - [ ] Tests updated (or not required). - [ ] Documentation updated (or not required).
Description:
Enhance errors reporting
SWC api
try_with_handleronly return anyhow!(msg) Err, it'a will lose many message about error stack, level ...,To express more error message in swc, we can return
Vec<Diagnostic>intry_with_handler;try_with_handler_diagnostic return a
Result<Ret, Vec<Diagnostic>>. Layer user can usingdiagnostic.codeto distinguish what kind error is.mietteas a dependency for improved error handling and reporting.miettefor pretty printing errors.ThreadSafetyDiagnosticsto manage and store diagnostics.miette.BREAKING CHANGE:
The api
try_with_handlerwould not return anyhow!(msg).It's will return TWithDiagnosticArray as it's Err. Then you can take diagnostics from TWithDiagnosticArray or get pretty string from it.
Related issue (if exists):
#10192