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

Consider reporting only the most specific error(s)? #278

Open
jenseng opened this issue Dec 18, 2023 · 1 comment
Open

Consider reporting only the most specific error(s)? #278

jenseng opened this issue Dec 18, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jenseng
Copy link

jenseng commented Dec 18, 2023

It would be great if only the most specific error(s) were reported. For example, given this GitHub Actions workflow file:

name: Push
on: push
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
      - runn: npm install # <-- whoopsie, a typo!
      - rn: npm run build # <-- uhoh, another one!
      - run: npm run test
      - run: npm run lint

You get the following errors:

   4:3  error  "jobs.test" must have required property 'uses'               json-schema-validator/no-invalid
   4:3  error  "jobs.test" must match exactly one schema in oneOf           json-schema-validator/no-invalid
   5:5  error  Unexpected property "jobs.test["runs-on"]"                   json-schema-validator/no-invalid
   6:5  error  Unexpected property "jobs.test.steps"                        json-schema-validator/no-invalid
  12:9  error  "jobs.test.steps[2]" must have required property 'uses'      json-schema-validator/no-invalid
  12:9  error  "jobs.test.steps[2]" must have required property 'run'       json-schema-validator/no-invalid
  12:9  error  "jobs.test.steps[2]" must match exactly one schema in oneOf  json-schema-validator/no-invalid
  12:9  error  Unexpected property "jobs.test.steps[2].runn"                json-schema-validator/no-invalid
  13:9  error  "jobs.test.steps[3]" must have required property 'uses'      json-schema-validator/no-invalid
  13:9  error  "jobs.test.steps[3]" must have required property 'run'       json-schema-validator/no-invalid
  13:9  error  "jobs.test.steps[3]" must match exactly one schema in oneOf  json-schema-validator/no-invalid
  13:9  error  Unexpected property "jobs.test.steps[3].rn"                  json-schema-validator/no-invalid

This can cause some confusion/churn; ideally just the Unexpected property "jobs.test.steps[2].runn" and Unexpected property "jobs.test.steps[3].rn" would get reported. I tried setting ajv's allErrors: false to reduce the noise, but that's worse (although the run error provides a good hint for the first typo, the second typo is not reported):

   4:3  error  "jobs.test" must have required property 'uses'               json-schema-validator/no-invalid
   4:3  error  "jobs.test" must match exactly one schema in oneOf           json-schema-validator/no-invalid
  12:9  error  "jobs.test.steps[2]" must have required property 'uses'      json-schema-validator/no-invalid
  12:9  error  "jobs.test.steps[2]" must have required property 'run'       json-schema-validator/no-invalid
  12:9  error  "jobs.test.steps[2]" must match exactly one schema in oneOf  json-schema-validator/no-invalid

I haven't dug into the code too deeply, but it seems like it should be possible to just keep the most specific errors (i.e. for each error we encounter, discard any errors from ancestor nodes). Perhaps this could be opt-in to start, WDYT? I'd be happy to create a PR if you're interested in this feature.

@ota-meshi
Copy link
Owner

Thank you for the feature suggestion.

I haven't dug into the code too deeply, but it seems like it should be possible to just keep the most specific errors (i.e. for each error we encounter, discard any errors from ancestor nodes). Perhaps this could be opt-in to start, WDYT? I'd be happy to create a PR if you're interested in this feature.

I welcome pull requests.

@ota-meshi ota-meshi added enhancement New feature or request help wanted Extra attention is needed labels Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants