Skip to content

Commit

Permalink
handled the document object being undefined in the parser result.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmit-coder committed Feb 5, 2024
1 parent 9b73229 commit 360f263
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions library/src/helpers/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,24 @@ export class Parser {
parserOptions?: any,
): Promise<ParserReturn> {
try {
const { document } = await asyncapiParser.parse(content, parserOptions);
return { asyncapi: document };
const parseResult = await asyncapiParser.parse(content, parserOptions);

let error: { title: string } = { title: '' };
if (parseResult.document === undefined) {
parseResult.diagnostics.forEach(diagnostic => {
if (diagnostic.code.toString().includes('error')) {
error.title = diagnostic.message.toString();
}
});

if (error.title === '') {
error.title = 'Unexpected error while parsing the document.';
}

throw error;
}

return { asyncapi: parseResult.document };
} catch (err) {
return this.handleError(err as ErrorObject);
}
Expand Down

0 comments on commit 360f263

Please sign in to comment.