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

feat(rome_js_analyze): handle serde errors inside RuleContext #3352

Merged
merged 13 commits into from
Oct 10, 2022

Conversation

ematipico
Copy link
Contributor

@ematipico ematipico commented Oct 6, 2022

Summary

Closes #3346

This PR does the following:

  • move away from RawValue and use Value for the time being; serde has a nasty issue where untagged macro doesn't work with RawValue. Fixing the issue in user land is not an easy task. So as for now, myself and @leops decided to use Value for the time being. This allows us to correctly parse options, but we would need to parse it again in order to type it correctly. This is temporary measure while we will find a good way to re-introduce RawValue. Link to the bug Internal buffering disrupts format-specific deserialization features serde-rs/serde#1183
  • create a new diagnostic called RuleContextDiagnostic which uses the new diagnostics, which emits errors in case deserialisation fails or the rule can't find the services needed from ServiceBag. Unfortunately I can't test the diagnostic yet because there's still some missing logic yet (creation of AnalyzerOptions from the Workspace). A test will be created once all the pieces are in place.
  • adds a type generic type to Rule called Options, which is used to dynamically type the options, which are retrieved using the method ctx.options(). Because of that, all the new rules had to be updated to take this new type into account.

Test Plan

The new logic is still not triggered, so the CI should just pass

@ematipico ematipico changed the title feat(rome_analyze): use serde to deserialize rule settings @ematipico feat(rome_js_analyze): handle serde errors inside RuleContext Oct 6, 2022
@ematipico ematipico changed the title @ematipico feat(rome_js_analyze): handle serde errors inside RuleContext feat(rome_js_analyze): handle serde errors inside RuleContext Oct 6, 2022
@ematipico ematipico force-pushed the feature/rule-with-self branch from bb271aa to 2f8980e Compare October 7, 2022 15:23
Base automatically changed from feature/rule-with-self to main October 10, 2022 07:31
@ematipico ematipico temporarily deployed to netlify-playground October 10, 2022 08:19 Inactive
@netlify
Copy link

netlify bot commented Oct 10, 2022

Deploy Preview for rometools ready!

Name Link
🔨 Latest commit 316aefd
🔍 Latest deploy log https://app.netlify.com/sites/rometools/deploys/6344387ca62f2e00089d6f1c
😎 Deploy Preview https://deploy-preview-3352--rometools.netlify.app
📱 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 marked this pull request as ready for review October 10, 2022 08:19
@calibre-analytics
Copy link

calibre-analytics bot commented Oct 10, 2022

Comparing feat(rome_js_analyze): handle serde errors inside RuleContext Snapshot #9 to median since last deploy of rome.tools.

LCP? CLS? TBT?
Overall
Median across all pages and test profiles
562ms
no change
0.049
no change
74ms
from 42ms
Chrome Desktop
Chrome Desktop • Cable
562ms
from 585ms
0.018
from 0.006
179ms
from 226ms
iPhone, 4G LTE
iPhone 12 • 4G LTE
277ms
from 220ms
0.077
no change
10ms
from 6ms
Motorola Moto G Power, 3G connection
Motorola Moto G Power • Regular 3G
682ms
from 557ms
0.049
no change
74ms
from 42ms

1 page tested

 Home

Browser previews

Chrome Desktop iPhone, 4G LTE Motorola Moto G Power, 3G connection
Chrome Desktop iPhone, 4G LTE Motorola Moto G Power, 3G connection

Most significant changes

Value Budget
Total JavaScript Size in Bytes
Chrome Desktop
1.24 MB
from 86.8 KB
Total JavaScript Size in Bytes
iPhone, 4G LTE
1.24 MB
from 86.8 KB
Total JavaScript Size in Bytes
Motorola Moto G Power, 3G connection
1.24 MB
from 86.8 KB
Number of Requests
Chrome Desktop
39
from 5
Number of Requests
iPhone, 4G LTE
39
from 5

4 other significant changes: Number of Requests on Motorola Moto G Power, 3G connection, Total Page Size in Bytes on Chrome Desktop, Total Page Size in Bytes on iPhone, 4G LTE, Total Page Size in Bytes on Motorola Moto G Power, 3G connection

Calibre: Site dashboard | View this PR | Edit settings | View documentation

@github-actions
Copy link

github-actions bot commented Oct 10, 2022

@ematipico ematipico requested a review from leops October 10, 2022 09:58
@ematipico ematipico temporarily deployed to netlify-playground October 10, 2022 09:58 Inactive
@ematipico ematipico temporarily deployed to netlify-playground October 10, 2022 10:16 Inactive
@@ -53,3 +55,51 @@ pub struct AnalyzerOptions {
/// A data structured derived from the [`rome.json`] file
pub configuration: AnalyzerConfiguration,
}

#[derive(Debug, Diagnostic)]
#[diagnostic(category = "internalError/io", tags(INTERNAL))]
Copy link
Contributor

Choose a reason for hiding this comment

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

The exact meaning of the INTERNAL tag is a bit vague, but in general I think it should be used for errors that are not caused by a direct action or input from the user. In this case, since this error results from deserializing a piece of user-provided input (the rome.json configuration file) so it doesn't really qualify as "internal"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed it. The only reason I had it there, was mostly because I copied the code the the examples/ folder. Thank you for catching it.

Self {
message: message.clone(),
description: message,
path: Resource::Memory,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to inject the path to the rome.json file here ? It would be more accurate but might incur a complex refactor though ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately we don't have that information yet... but we might able to get something out, once we merge #3381

At the moment the analyzer doesn't have any awareness at all, we need to construct AnalyzerOptions to hold all the information we need, including the path to the configuration. We don't have this info yet (neither the Workspace has it, at the time of writing)

@ematipico ematipico requested a review from leops October 10, 2022 15:20
@ematipico ematipico temporarily deployed to netlify-playground October 10, 2022 15:21 Inactive
@ematipico ematipico merged commit 5058cf8 into main Oct 10, 2022
@ematipico ematipico deleted the feature/handle-serde-error branch October 10, 2022 15:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

handle error emitted by serde
2 participants