Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit cbd8ea0

Browse files
committed
fix(oas3): improve YAML error message descriptions
1 parent 248f0f2 commit cbd8ea0

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

packages/fury-adapter-oas3-parser/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
- Fixes the parser from throwing an error while handling invalid or unsupported
1111
security scheme components.
1212

13+
- Added additional information to YAML parsing errors where available to make
14+
the errors more understandable.
15+
1316
## 0.7.2 (2019-04-01)
1417

1518
### Bug Fixes

packages/fury-adapter-oas3-parser/lib/parser/parseYAML.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,17 @@ function parse(source, context) {
106106
try {
107107
ast = yaml.compose(source);
108108
} catch (error) {
109+
let message;
110+
111+
if (error.problem) {
112+
const problem = error.problem.replace('\t', '\\t');
113+
message = `${problem}, ${error.context}`;
114+
} else {
115+
message = error.context;
116+
}
117+
109118
const annotation = new namespace.elements.Annotation(
110-
`YAML Syntax: ${error.context}`,
119+
`YAML Syntax: ${message}`,
111120
{ classes: ['error'] }
112121
);
113122

packages/fury-adapter-oas3-parser/test/unit/parser/parseYAML-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('#parseYAML', () => {
2929
expect(parseResult).to.be.instanceof(namespace.elements.ParseResult);
3030
expect(parseResult.errors.length).to.equal(1);
3131

32-
expect(parseResult).contain.error('YAML Syntax: while scanning for the next token').with.sourceMap([[14, 0]]);
32+
expect(parseResult).contain.error('YAML Syntax: found character \\t that cannot start any token, while scanning for the next token').with.sourceMap([[14, 0]]);
3333
});
3434
});
3535

0 commit comments

Comments
 (0)