bug(apidom-parser-adapter-yaml-1-2): Change message returned for syntax errors #2914
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 changes the error message returned by
apidom-parser-adapter-yaml-1-2
when it encounters a Syntax error.Description
This PR does the following:
Motivation and Context
closes #2889
Currently if
apidom-parser-adapter-yaml-1-2
encounters Syntax errors in YAML definition it returns the ERROR node as an error message which is not useful information from user perspective, that's why it would be better to return the message "YAML Syntax error"The initial idea to solve this issue was to check if the error message value is an ERROR node containing part of YAML definition and then replace the message with "YAML Syntax error" when processing an error found during parsing.
When investigating this issue and discussing it with Vladimir we decided that in terms of syntax errors, we do not need to check this in code because every error found on this level is a syntax error so we can just return a static error message there.
To make sure that there wasn't any useful information returned from the parser we are using I tested different structures used in YAML 1.2.2 (using
swagger-editor
5.0.0-alpha.67) to check what error messages I get when introducing a syntax error.Tested examples (found in https://yaml.org/spec/1.2.2):
In every scenario, I tried to cause a syntax error by removing indentation or part of correct YAML syntax (e.g. dash and space for block sequences or colon and space for mappings) which caused an ERROR node to be returned with part of YAML definition (elements with same scope/indentation above the part that causes the error or in some cases the same line e.g. when removing square brackets from flow sequence, curly braces from flow mapping or quote marks from quoted scalars).
How Has This Been Tested?
It has been tested by adding new unit tests in the package folder.
Checklist
My PR contains...
src/
is unmodified: changes to documentation, CI, metadata, etc.)package.json
)My changes...
Documentation
Automated tests