Skip to content

Commit

Permalink
Enhance type safety in validate function's error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaith committed Oct 7, 2024
1 parent a684894 commit ea9f9c3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class Visitor implements SchemaVisitor<Node> {
}
}



export function validate(data: string): boolean {
try {
const stream = CharStreams.fromString(data);
Expand All @@ -92,8 +94,11 @@ export function validate(data: string): boolean {
visitor.visit(ast);
return true;
} catch (error) {
const err = error as Error;
console.error(err.message);
if (error instanceof Error) {
console.error(error.message);
} else {
console.error(String(error));
}
return false;
}
}

0 comments on commit ea9f9c3

Please sign in to comment.