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

refactor: error and diagnostics #4866

Merged
merged 1 commit into from
Dec 8, 2023
Merged

Conversation

h-a-n-a
Copy link
Collaborator

@h-a-n-a h-a-n-a commented Dec 4, 2023

Summary

This chain of PRs are intended to solve problems related to errors/diagnostics as follows.

InternalErrors are abusively used across rspack crates. However these errors
should provide more useful context. See: #4613, #4321.
Diagnostics in rspack is represented by another custom type
to be fed to codespan-reporting in reporting. This indicates that errors
should be converted in the first place in order to be consumed by Stats.

In the following PRs, the essential idea to solve the problems are as follows:

  1. miette and thiserror: This pair of libraries can either make fancy diagnostics and create easy to read errors. GraphicalReportHandler of miette can be helpful to directly print error diagnostics.
  2. codespan-reporting is removed as rspack will never rely on custom diagnostics anymore
  3. Custom error code to maximize the compatibility with Webpack's error types
  4. Improved webpack error overlay

Some miscellaneous are included in the graphite stack. Take a look over the PR tree down below.

This PR did some small initialization works.

Test Plan

Require Documentation?

  • No
  • Yes, the corresponding rspack-website PR is __

@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Dec 4, 2023
@h-a-n-a h-a-n-a force-pushed the 12-04-refactor_error_and_diagnostics branch from 5d15894 to 6b52494 Compare December 4, 2023 10:38
@h-a-n-a h-a-n-a force-pushed the 12-04-refactor_error_and_diagnostics branch 2 times, most recently from 11bdaf9 to 4c359da Compare December 4, 2023 13:20
@h-a-n-a h-a-n-a mentioned this pull request Dec 4, 2023
2 tasks
@h-a-n-a h-a-n-a force-pushed the 12-04-refactor_error_and_diagnostics branch from 3406e7f to 4c359da Compare December 5, 2023 04:51
@h-a-n-a h-a-n-a force-pushed the 12-04-refactor_error_and_diagnostics branch 2 times, most recently from 35be7b3 to 2247eee Compare December 5, 2023 07:58
@h-a-n-a h-a-n-a mentioned this pull request Dec 6, 2023
2 tasks
@h-a-n-a h-a-n-a force-pushed the 12-04-refactor_error_and_diagnostics branch from 2247eee to b6ff92e Compare December 7, 2023 10:57
@h-a-n-a h-a-n-a force-pushed the 12-04-refactor_error_and_diagnostics branch from b6ff92e to 8deb971 Compare December 8, 2023 03:55
@h-a-n-a h-a-n-a self-assigned this Dec 8, 2023
@h-a-n-a h-a-n-a marked this pull request as ready for review December 8, 2023 04:39
@h-a-n-a h-a-n-a requested review from a team December 8, 2023 04:39
@h-a-n-a h-a-n-a merged commit 406f2b8 into main Dec 8, 2023
17 checks passed
@h-a-n-a h-a-n-a deleted the 12-04-refactor_error_and_diagnostics branch December 8, 2023 06:06
h-a-n-a added a commit that referenced this pull request Dec 8, 2023
…4892)

<!--
  Thank you for submitting a pull request!

  We appreciate the time and effort you have invested in making these changes. Please ensure that you provide enough information to allow others to review your pull request.

  Upon submission, your pull request will be automatically assigned with reviewers.

  If you want to learn more about contributing to this project, please visit: https://github.com/web-infra-dev/rspack/blob/main/CONTRIBUTING.md.
-->

## Summary

Based on the overall idea behind this in #4866. 

This PR leverages `miette` and `thiserror` for representing errors and diagnostics.
This makes aligning with webpack errors easily. 

1. `miette::Error` as `rspack_error::Error`
2. `miette::Error` as `Diagnostic`
3. `Result<T> = std::result::Result<T, miette::Error>`
4. Print diagnostics with `miette::GraphicalReportHandler`
5. Eagerly deduped ecma errors on site, and remove `PartialEq`, etc from `Diagnostics`.
6. Refactored one Webpack Error to diagnostic representation, use https://github.com/web-infra-dev/rspack/pull/4892/files#diff-b6b8b1bb36b909de2bbe46c5de8c4c34515cb1c9710e8d02faec369b352da525R167 as an example

Minor changes:
1. Removed `clippy::unwrap_in_result` as previously discussed.

<!-- Can you explain the reasoning behind implementing this change? What problem or issue does this pull request resolve? -->

<!-- It would be helpful if you could provide any relevant context, such as GitHub issues or related discussions. -->

## Test Plan

See snapshot changes.

<!-- Can you please describe how you tested the changes you made to the code? -->

## Require Documentation?

<!-- Does this PR require documentation? -->

- [X] No
- [ ] Yes, the corresponding rspack-website PR is \_\_
@h-a-n-a h-a-n-a mentioned this pull request Dec 18, 2023
2 tasks
@h-a-n-a h-a-n-a mentioned this pull request Dec 19, 2023
2 tasks
ahabhgk pushed a commit that referenced this pull request Jan 2, 2024
<!--
  Thank you for submitting a pull request!

  We appreciate the time and effort you have invested in making these changes. Please ensure that you provide enough information to allow others to review your pull request.

  Upon submission, your pull request will be automatically assigned with reviewers.

  If you want to learn more about contributing to this project, please visit: https://github.com/web-infra-dev/rspack/blob/main/CONTRIBUTING.md.
-->

## Summary

This chain of PRs are intended to solve problems related to errors/diagnostics as follows.

`InternalErrors` are abusively used across rspack crates. However these errors
should provide more useful **context**. See: #4613, #4321.
`Diagnostics` in rspack is represented by another custom type
to be fed to `codespan-reporting` in reporting. This indicates that errors
should be converted in the first place in order to be consumed by `Stats`.

In the following PRs, the essential idea to solve the problems are as follows:

1. `miette` and `thiserror`: This pair of libraries can either make fancy diagnostics and create easy to read errors. `GraphicalReportHandler` of `miette` can be helpful to directly print error diagnostics.
2. `codespan-reporting` is removed as rspack will never rely on custom diagnostics anymore
3. Custom error code to maximize the compatibility with Webpack's error types
4. Improved webpack error overlay

Some miscellaneous are included in the graphite stack. Take a look over the PR tree down below.

**This** PR did some small initialization works.

<!-- Can you explain the reasoning behind implementing this change? What problem or issue does this pull request resolve? -->

<!-- It would be helpful if you could provide any relevant context, such as GitHub issues or related discussions. -->

## Test Plan

<!-- Can you please describe how you tested the changes you made to the code? -->

## Require Documentation?

<!-- Does this PR require documentation? -->

- [ ] No
- [x] Yes, the corresponding rspack-website PR is \_\_
ahabhgk pushed a commit that referenced this pull request Jan 2, 2024
…4892)

<!--
  Thank you for submitting a pull request!

  We appreciate the time and effort you have invested in making these changes. Please ensure that you provide enough information to allow others to review your pull request.

  Upon submission, your pull request will be automatically assigned with reviewers.

  If you want to learn more about contributing to this project, please visit: https://github.com/web-infra-dev/rspack/blob/main/CONTRIBUTING.md.
-->

## Summary

Based on the overall idea behind this in #4866. 

This PR leverages `miette` and `thiserror` for representing errors and diagnostics.
This makes aligning with webpack errors easily. 

1. `miette::Error` as `rspack_error::Error`
2. `miette::Error` as `Diagnostic`
3. `Result<T> = std::result::Result<T, miette::Error>`
4. Print diagnostics with `miette::GraphicalReportHandler`
5. Eagerly deduped ecma errors on site, and remove `PartialEq`, etc from `Diagnostics`.
6. Refactored one Webpack Error to diagnostic representation, use https://github.com/web-infra-dev/rspack/pull/4892/files#diff-b6b8b1bb36b909de2bbe46c5de8c4c34515cb1c9710e8d02faec369b352da525R167 as an example

Minor changes:
1. Removed `clippy::unwrap_in_result` as previously discussed.

<!-- Can you explain the reasoning behind implementing this change? What problem or issue does this pull request resolve? -->

<!-- It would be helpful if you could provide any relevant context, such as GitHub issues or related discussions. -->

## Test Plan

See snapshot changes.

<!-- Can you please describe how you tested the changes you made to the code? -->

## Require Documentation?

<!-- Does this PR require documentation? -->

- [X] No
- [ ] Yes, the corresponding rspack-website PR is \_\_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants