Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_service): internal errors as diagnostics #3921

Merged
merged 4 commits into from
Dec 8, 2022

Conversation

ematipico
Copy link
Contributor

Summary

This PR implements the trait Diagnostic to the enum RomeError. This change doesn't change the current logic of how the errors are printed to the console.

List of the changes:

  • the various errors defined in the multiple crates have been moved inside a generic file called diagnostics.rs, and it seems a generic pattern we are adopting across the code base
  • insta has been moved into the workspace, so we have one single version across the code base
  • some errors have been slightly changed, for example, the ConfigurationError, so more and better information can be printed using the Diagnostic trait
  • the messages inside the message() and description() functions are a copy-paste from the Display trait, and I intend to keep them this way. We can review the messaging once the transition is completed and we print these diagnostics in the CLI
  • various errors have now snapshot tests, to show people how they will look like once the transition is finished (not in this PR)

These changes are safe and can be merged whenever.

Test Plan

I created new snapshots to show the look and file of the changes.
The current tests of the CLI should stay the same.

@netlify
Copy link

netlify bot commented Dec 2, 2022

Deploy Preview for docs-rometools ready!

Name Link
🔨 Latest commit d882a7c
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/639090e93c10a300095c47d7
😎 Deploy Preview https://deploy-preview-3921--docs-rometools.netlify.app/playground
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@ematipico ematipico added A-Diagnostic Area: errors and diagnostics A-Core Area: core labels Dec 2, 2022
@ematipico ematipico force-pushed the feat/rome-error-diagnostic branch 2 times, most recently from 45f1fda to e0ee01e Compare December 2, 2022 13:41
crates/rome_service/src/configuration/mod.rs Show resolved Hide resolved
)
}
}
RomeError::FormatError(err) => err.message(f),
Copy link
Contributor

Choose a reason for hiding this comment

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

For diagnostics that contain an error, it might be more readable to print a message here (like "the formatter encountered an error while formatting the file" as we do in the Display implementation) and return the inner error as the source for this diagnostic (but this may not be possible currently since the Error type does not implement AsRef<dyn Diagnostic>)

Copy link
Contributor Author

@ematipico ematipico Dec 5, 2022

Choose a reason for hiding this comment

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

I changed the message but, as you thought, the source could not be used

crates/rome_service/src/file_handlers/mod.rs Outdated Show resolved Hide resolved
crates/rome_service/src/snapshots/cant_read_directory.snap Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Dec 5, 2022

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45879 45879 0
Passed 44936 44936 0
Failed 943 943 0
Panics 0 0 0
Coverage 97.94% 97.94% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 1707 1707 0
Failed 4239 4239 0
Panics 0 0 0
Coverage 28.71% 28.71% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12397 12397 0
Failed 3860 3860 0
Panics 0 0 0
Coverage 76.26% 76.26% 0.00%

@ematipico ematipico force-pushed the feat/rome-error-diagnostic branch 3 times, most recently from 0c0e6b4 to 150c6d3 Compare December 5, 2022 11:16
@ematipico ematipico requested a review from leops December 7, 2022 13:09
@ematipico ematipico merged commit 628a2de into main Dec 8, 2022
@ematipico ematipico deleted the feat/rome-error-diagnostic branch December 8, 2022 08:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Core Area: core A-Diagnostic Area: errors and diagnostics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants