Skip to content

Conversation

BillyONeal
Copy link
Member

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:

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>

…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>
```
@ras0219-msft ras0219-msft requested a review from Copilot May 8, 2025 16:59
Copy link

@Copilot Copilot AI left a 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));
}

Copy link
Preview

Copilot AI May 8, 2025

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.

Suggested change
// 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.

Comment on lines 47 to 48
void add_extra_field_error(const LocalizedString& type, StringView fields, StringView suggestion = {});
void add_generic_error(const LocalizedString& type, StringView message);
Copy link
Preview

Copilot AI May 8, 2025

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.

Suggested change
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.

@BillyONeal BillyONeal merged commit 3c8b58b into microsoft:main May 8, 2025
7 checks passed
@BillyONeal BillyONeal deleted the bad-feature-name-error-message branch May 8, 2025 19:28
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.

2 participants