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

fix: handled the document object being undefined in the parser result. #912

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading