-
Notifications
You must be signed in to change notification settings - Fork 317
Improve invalid feature name reporting #1675
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
Improve invalid feature name reporting #1675
Conversation
…re name rather than as part of the overall features block. Before and after demonstration: ``` PS C:\Dev\vcpkg-tool\out\build\Win-x64-Debug-WithArtifacts> type C:\Dev\vcpkg-tool\azure-pipelines\e2e-ports\vcpkg-requires-feature\vcpkg.json { "name": "vcpkg-requires-feature", "version": "0", "features": { "a": { "description": "Feature A" }, "b": { "description": "Feature B" }, "b_required": { "description": "This feature needs to be turned on for the port to build" }, "c": { "description": "Feature C" } } } PS C:\Dev\vcpkg-tool\out\build\Win-x64-Debug-WithArtifacts> C:\Dev\vcpkg\vcpkg.exe format-manifest C:\Dev\vcpkg-tool\azure-pipelines\e2e-ports\vcpkg-requires-feature\vcpkg.json C:\Dev\vcpkg-tool\azure-pipelines\e2e-ports\vcpkg-requires-feature\vcpkg.json: error: $.features (a set of features): features must be lowercase alphanumeric+hyphens, and not one of the reserved names PS C:\Dev\vcpkg-tool\out\build\Win-x64-Debug-WithArtifacts> .\vcpkg.exe format-manifest C:\Dev\vcpkg-tool\azure-pipelines\e2e-ports\vcpkg-requires-feature\vcpkg.json C:\Dev\vcpkg-tool\azure-pipelines\e2e-ports\vcpkg-requires-feature\vcpkg.json: error: $.features.b_required (a feature): features must be lowercase alphanumeric+hyphens, and not one of the reserved names PS C:\Dev\vcpkg-tool\out\build\Win-x64-Debug-WithArtifacts> ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors how invalid feature names are reported, ensuring that error messages are associated with the specific feature rather than the overall features block.
- Changed error reporting in feature parsing to use a field-level error handler instead of a generic error.
- Introduced a new function add_field_name_error in both the JSON reader implementation and header.
- Updated end-to-end tests to verify the new error reporting message format.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/vcpkg/sourceparagraph.cpp | Replaces generic error reporting with field-specific error reporting for invalid feature names. |
src/vcpkg/base/json.cpp | Adds a new add_field_name_error method that wraps generic error reporting with additional context. |
include/vcpkg/base/jsonreader.h | Declares the new add_field_name_error method. |
azure-pipelines/end-to-end-tests-dir/format-manifest.ps1 | Updates test expectations to reflect the new error message format. |
azure-pipelines/e2e-assets/format-manifest-malformed/bad-feature-name.json | Provides a sample manifest to trigger the new error reporting. |
Comments suppressed due to low confidence (2)
azure-pipelines/end-to-end-tests-dir/format-manifest.ps1:21
- [nitpick] Ensure that this test case remains valid if the error message wording is refined further in future updates, as it specifically checks the new field-level error message format.
$output = Run-VcpkgAndCaptureOutput @commonArgs format-manifest "$PSScriptRoot/../e2e-assets/format-manifest-malformed/bad-feature-name.json"
src/vcpkg/sourceparagraph.cpp:1111
- This change improves error reporting by tying the error specifically to the feature name. Verify that the new error message format fully meets the documented requirements for invalid feature names.
r.add_field_name_error(
@@ -1492,6 +1492,12 @@ namespace vcpkg::Json | |||
.append_raw(message)); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider adding inline documentation here to explain that add_field_name_error wraps the generic error logic while providing additional context from the field name.
// This function wraps add_generic_error while temporarily appending the field name to the path. | |
// It provides additional context by including the field name in the error message. |
Copilot uses AI. Check for mistakes.
void add_extra_field_error(const LocalizedString& type, StringView fields, StringView suggestion = {}); | ||
void add_generic_error(const LocalizedString& type, StringView message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] It would be beneficial to add a comment describing the purpose of add_field_name_error and how it differs from add_generic_error.
void add_extra_field_error(const LocalizedString& type, StringView fields, StringView suggestion = {}); | |
void add_generic_error(const LocalizedString& type, StringView message); | |
void add_extra_field_error(const LocalizedString& type, StringView fields, StringView suggestion = {}); | |
// Reports a general error related to the JSON object, not tied to a specific field. | |
void add_generic_error(const LocalizedString& type, StringView message); | |
// Reports an error related to a specific field name in the JSON object. | |
// Use this method when the error pertains to a particular field, such as a missing or invalid value. |
Copilot uses AI. Check for mistakes.
When a feature name is invalid, report the error as part of the feature name rather than as part of the overall features block.
Before and after demonstration: