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: improve validation-error.ts file #178

Merged
merged 8 commits into from
Feb 9, 2022
13 changes: 11 additions & 2 deletions src/errors/validation-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,24 @@ export class ValidationError extends Error {
for (const e of err.validationErrors) {
const errorHasTitle = !!e.title;
const errorHasLocation = !!e.location;
if (errorHasLocation) {
/*
* All the conditions below are needed since validationErrors (from ParserError) come from Parser JS library,
* so we cannot assure that all the fields or properties are always provided in the error. There might be cases
* that even title is not provided.
*/
if (errorHasTitle && errorHasLocation) {
errorsInfo.push(`${e.title} ${e.location.startLine}:${e.location.startColumn}`);
continue;
}
if (errorHasTitle) {
errorsInfo.push(`${e.title}`);
continue;
}
if (errorHasLocation) {
errorsInfo.push(`${e.location.startLine}:${e.location.startColumn}`);
}
}
}

this.message = errorsInfo.join('\n');
}
}