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

feat(config): better error messages around schema validation #4889

Merged
merged 14 commits into from Sep 26, 2023
Merged

Conversation

edvald
Copy link
Collaborator

@edvald edvald commented Jul 25, 2023

This attaches the YAML parse results to configs when loading, and leverages that when rendering validation error messages.

...
3  | spec:
4  |   foo: 123
-------^
"foo" should be a string

This should be a useful step for an IDE highlighting integration as well.

Copy link
Collaborator

@vvagaytsev vvagaytsev left a comment

Choose a reason for hiding this comment

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

There are some test failures, please take a look.

@TimBeyer
Copy link
Contributor

Does this work as expected with YAML files that contain multiple docs?
When I was trying this out you needed to do something like

const lineCounter = new LineCounter()
const parser = new Parser(lineCounter.addNewLine)

const tokens = parser.parse(content)
const docsGenerator = new Composer().compose(tokens)

const docs = Array.from(docsGenerator) as Document.Parsed<ParsedNode>[]

to get the docs and then use lineCounter.linePos to get the correct line in the input file.

@edvald
Copy link
Collaborator Author

edvald commented Jul 25, 2023

I hadn't tested that specifically, good catch. Not sure I fully follow your code there though. Happy to take commits on this PR btw, it's very much a draft still, bunch of broken tests etc.

@thsig
Copy link
Collaborator

thsig commented Jul 31, 2023

Btw, in case it simplifies the implementation I think it's acceptable if we just show the YAML doc/subdoc that the error came from, even it it's a sub-doc of a larger one—we just need to help the user quickly pinpoint the source location.

yamlDocBasePath = ["providers", i]
return false
}
return true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this statement always break the loop after the first iteration? Was it done intentionally? It looks like the returned boolean value is never used, do we need it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's intentional. The boolean needs to be there, linter complains if we only return it to break.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, got it, thanks! It may make sense to leave a short comment on that :)

@vvagaytsev
Copy link
Collaborator

I left a few comments and questions, please check.
Otherwise looks good, thank you! 👍

vvagaytsev
vvagaytsev previously approved these changes Sep 4, 2023
Copy link
Collaborator

@vvagaytsev vvagaytsev left a comment

Choose a reason for hiding this comment

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

LGTM! 👍 Thanks for the great improvement! 💯

@vvagaytsev
Copy link
Collaborator

@edvald would you have time to resolve the conflicts soon? I can also take a look, please let me know if you need to hand this over. It would be nice to include it in one of the upcoming releases.

@edvald
Copy link
Collaborator Author

edvald commented Sep 21, 2023

Just did that actually, good timing :) Just grappling with my merge commit now.

@edvald
Copy link
Collaborator Author

edvald commented Sep 21, 2023

Ok, should be ready now, pending tests passing.

@vvagaytsev
Copy link
Collaborator

Now there are more conflicts to be resolved.

@edvald
Copy link
Collaborator Author

edvald commented Sep 25, 2023

Updated again.

Comment on lines +88 to +90
path: ObjectPath | undefined
value: any
resolved: any
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like these parameters are never rendered. Do we need this specific kind of error? Or should we just use ConfigurationError class instead?
@stefreak @TimBeyer wdyt?

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 opted to keep this even though the typed detail object was removed, since we are likely to use this (and potentially more) later for e.g. a language server implementation.

Copy link
Collaborator

@vvagaytsev vvagaytsev left a comment

Choose a reason for hiding this comment

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

Thank you! 💯

@edvald edvald added this pull request to the merge queue Sep 26, 2023
Merged via the queue into main with commit a098a14 Sep 26, 2023
41 checks passed
@edvald edvald deleted the parse-trace branch September 26, 2023 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants