[vcpkg] Improve Json error messages#12981
Merged
ras0219-msft merged 5 commits intomicrosoft:masterfrom Sep 7, 2020
Merged
Conversation
strega-nil
suggested changes
Aug 21, 2020
Contributor
strega-nil
left a comment
There was a problem hiding this comment.
This is the only thing I see that's easy to change. However, I have a lot of changes in #13038 that I don't particularly wish to merge with this, since they both make a lot of the same changes. I'd rather merge that one first because this is going to be easier to merge later.
Contributor
Author
|
Converting to draft until #13038 has been merged according to @strega-nil's preference |
dc7f840 to
21736c5
Compare
strega-nil
approved these changes
Sep 4, 2020
Contributor
strega-nil
left a comment
There was a problem hiding this comment.
This is a really great changeset :D
6796d7a to
087fbe6
Compare
Contributor
Author
|
I reverted the line break change because it does not comply with our clang-format rules; if we want to change the rules I think it would be best to do it in another PR. |
Contributor
|
Thanks for the reviews! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves error messages reported by the JSON parser; specifically when handling manifests.
This includes a fundamental shift away from the existing error approach taken by the CONTROL-file code because that approach is inappropriate for a JSON world. The CONTROL file format is specifically a very flat format, so explicitly printing a list of valid fields makes sense because there's only one context for fields[1].
JSON, on the other hand, is a fundamentally different beast with its hierarchical objects and arrays and therefore merits a different strategy. In this PR, I've approached the problem similar to compiler error messages which are better designed for a tree-based structure. Explaining the full possible schema in the error output would be extremely verbose, so instead I've opted to link users to the current best documentation (docs/specifications/manifests.md and docs/specifications/registries.md). When we have more polished docs for these file types, these links can be updated to point there.
To help users locate the errors within their files, I've opted to use a JSONPath-style location; potential future work would be to add source location tracking into the JSON nodes to enable proper "Go To Error" in editors such as Visual Studio Code.
As a drive by, this also fixes a regression in start-of-line tracking.
[1] Feature paragraphs are close enough to Source paragraphs that the valid field list is not great but still works.
Example 1:
{ "name": "abseil", "version-string": "2020-03-03", "port-version": 8, "description": "a", "homepage": "https://github.com/abseil/abseil-cpp", "features": [ { "name": "cxx17", "description": "Enable compiler C++17." } ], "dependencies": [ [], "a", { "b": 1 } ] }Before:
After:
Example 2:
{ "name": "abseil", "version-string": "2020-03-03", "port-version": 8, "description": "abc", "homepage": "https://github.com/abseil/abseil-cpp", "features": [ { "name": "cxx17", "decsription": "Enable compiler C++17." } ] }Before:
After:
Example 4:
{ "name": "abseil", "version-string": "2020-03-03", "port-version": 8, "description": "abc", "homepage": "https://github.com/abseil/abseil-cpp", "features": [ { "name": ["cxx17"], "description": "Enable compiler C++17." } ] }Before:
After:
Example 5:
{ "name": "abseil", "version-string": "2020-03-03", "port-version": 8, "description": "abc", "homepage": "https://github.com/abseil/abseil-cpp", "features": [ { "name": "cxx17", "description": "Enable compiler C++17.", } ] }Before:
After:
Example 6 (
vcpkg-configuration.json):{ "a":1 }Before:
After:
Example 7:
{ "name": "abseil", "version-string": "2020-03-03", "description": "", "dependencies": [ { "name": "foo", "paltform": "linux", "platform": "linux" } ] }Before (Note: the valid field 'platform' is not listed anywhere in the list of valid fields):
After: