redhat-developer / redhat-developer/vscode-yaml

Failure to gracefully handle empty items definitions on array properties

Open
#1,121 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
829
Forks
260
Avg merge
5h 43m
Merged PRs (30d)
1

Description

Describe the bug

The extension generates exceptions when viewing, and fails to provide validation to, files that reference a schema defining an object with an array property that is missing a value for the items definition.

file1.yaml

# yaml-language-server: $schema=http://json-schema.org/draft-07/schema#
$schema: 'http://json-schema.org/draft-07/schema#'

ObjectSchema:
  type: object
  properties:
    refProp:
      type: array
      items: # an array with an empty items property causes exceptions that break validation

file2.yaml

# yaml-language-server: $schema=./file1.yaml#/ObjectSchema

refProp: true # should be highlighted as an incorrect type if validation is working 

Expected Behavior

I would expect the empty items: property to be higlighted as invalid, assuming it is indeed invalid JSON-schema according to the schema set as the language server schema for file1. If it is not invalid (though I'm sure it must be), then it shouldn't cause a problem for the extension when loading it as part of parsing and validating file2.

Current Behavior

Validation simply fails to function, and exceptions are thrown by the extension.

Steps to Reproduce

  1. Create the two files shown above
  2. Open file2 and observe the failure to highlight the error of the invalid property value type.
  3. Open VS Code's Output pane and set the content to Window, then hover over the refProp name, observe the exception that is generated by the extension.
  4. Now comment out the items: line in file1 (or provide a valid item spec), restart the extension host to load the updated schema and go back to file2 and note that validation is now working as expected.

Environment

  • Windows
  • Mac
  • Linux
  • other (please specify)

Extension version: 1.18.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Recreate file1.yaml and file2.yaml from the report, then inspect the VS Code Output pane while opening file2 to reproduce the exception. Trace schema parsing and validation for the empty items definition; done means the extension no longer throws and refProp is flagged for its incorrect boolean value.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.