Skip to content

Better Yaml Errors #499

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

Merged
merged 13 commits into from
Sep 28, 2022
Merged

Better Yaml Errors #499

merged 13 commits into from
Sep 28, 2022

Conversation

rydrman
Copy link
Collaborator

@rydrman rydrman commented Sep 6, 2022

The goal was to create error messages which were longer and more expressive during the yaml deserialization process. I'm using an existing crate which nicely formats the yaml errors with positional information and original context (with color).

image

I think there's probably much more that we could do, but this first pass required replacing all of the previous custom deserialization code with proper serde::de::Visitor types that allow the deserializer to retain positional information for errors. I've also done my best to validate data as much as possible during the first pass of the deserializer so that any issues are flagged in line to the actual issue in yaml - though this is not possible across the board because of some of the validation that we do.

We also still have the issue of unhelpful errors from nom, but this should help place them in the yaml to help with context.

@rydrman rydrman added enhancement New feature or request QoL quality of life fixes labels Sep 6, 2022
@rydrman rydrman requested review from jrray and paxsonsa September 6, 2022 05:29
@rydrman rydrman self-assigned this Sep 6, 2022
@rydrman
Copy link
Collaborator Author

rydrman commented Sep 6, 2022

I need to do a rebase on this, but it's in a state to be opened for thoughts either way

@rydrman
Copy link
Collaborator Author

rydrman commented Sep 6, 2022

Okay, this is up-to-date now

@codecov
Copy link

codecov bot commented Sep 6, 2022

Codecov Report

Merging #499 (bfb987a) into clippy-updates (43d1609) will increase coverage by 0.16%.
The diff coverage is 74.29%.

@@                Coverage Diff                 @@
##           clippy-updates     #499      +/-   ##
==================================================
+ Coverage           67.54%   67.70%   +0.16%     
==================================================
  Files                 276      278       +2     
  Lines               18869    19148     +279     
==================================================
+ Hits                12745    12965     +220     
- Misses               6124     6183      +59     
Impacted Files Coverage Δ
crates/spk-build/src/build/binary_test.rs 97.18% <ø> (ø)
crates/spk-cli/common/src/flags.rs 29.11% <0.00%> (-0.13%) ⬇️
crates/spk-schema/src/error.rs 50.00% <ø> (ø)
crates/spk-schema/src/package_test.rs 100.00% <ø> (ø)
crates/spk-storage/src/error.rs 0.00% <ø> (ø)
crates/spk-storage/src/storage/runtime.rs 25.67% <0.00%> (-0.54%) ⬇️
...s/foundation/src/ident_component/component_spec.rs 75.34% <42.85%> (-7.02%) ⬇️
...spk-schema/crates/foundation/src/version/compat.rs 77.24% <42.85%> (-1.64%) ⬇️
...es/spk-schema/crates/foundation/src/version/mod.rs 84.23% <42.85%> (-1.80%) ⬇️
crates/spk-schema/crates/ident/src/ident.rs 68.91% <42.85%> (-1.72%) ⬇️
... and 28 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@jrray jrray left a comment

Choose a reason for hiding this comment

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

Sorry for the long wait. This is really great stuff, looking forward to having it in our build.

Comment on lines +520 to +523
// unrecognized fields are explicitly ignored in case
// they were added in a newer version of spk. We assume
// that if the api has not been versioned then the desire
// is to continue working in this older version
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to know the spec version at this point? Someone could construct a spec file that has the version specified at the bottom of the file. I'm just thinking that if the spec version is known then this could be pickier about seeing unexpected content.

I would like a warning emitted for unexpected content to help catch typo bugs too. But it would be nice if those were enabled only in some contexts, like parsing a spec during a build, so these kinds of mistakes are caught early during dev but don't pester the end users of broken packages that they don't control.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ya, not without requiring that the spec version be at the top of the file (which we could do, but is not really to the yaml spec). Actually, even in that case, we would not have a good way to pass that information into this deserialize code - not impossible but I imagine it would be quite involved...

_ => {
// for forwards compatibility we ignore any unrecognized
// field, but consume it just the same
// TODO: could we check for possible typos in here?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Continuing my thoughts above, if these are warnings that get logged to a specific different channel then that channel can be enabled during a build so devs see them, and then not emitted when parsing packages during normal solves.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree - there are a lot of places that we could use a separate tracing level/target for build-time warnings to devs. I haven't looked into how one might do that with the tracing package, but even just a labelled span for parsing-from-a-file plus some extra logic at log initialization might do...

@rydrman rydrman mentioned this pull request Sep 27, 2022
9 tasks
rydrman and others added 13 commits September 26, 2022 21:14
Signed-off-by: Ryan Bottriell <[email protected]>
Using the serde_yaml crate directly is not advisable anymore because the
errors need to be wrapped in order to use the extended
format_serde_error functionality. A simply FromYaml trait with a blanket
implementation takes care of this for us while also supporting the
custom double-parsing that's required by the api versioning

Signed-off-by: Ryan Bottriell <[email protected]>
Signed-off-by: Ryan Bottriell <[email protected]>

Co-authored-by: jrray <[email protected]>
@rydrman rydrman changed the base branch from master to clippy-updates September 27, 2022 04:15
@rydrman
Copy link
Collaborator Author

rydrman commented Sep 27, 2022

I'll merge this once #514 goes in

Base automatically changed from clippy-updates to master September 27, 2022 23:27
@rydrman rydrman merged commit 25a002a into master Sep 28, 2022
@rydrman rydrman deleted the better-yaml-errors branch September 28, 2022 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request QoL quality of life fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants