Skip to content

Commit 387e77c

Browse files
committed
feat: Logs on load error
1 parent c8092e6 commit 387e77c

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/lib/Unifier.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,26 @@ export class JsonSchemaUnifier {
7474

7575
private async loadSchema(schemaPath: string) {
7676
if (this.schemata[schemaPath].schema) return this.schemata[schemaPath].schema;
77-
this.log("Loading", schemaPath);
78-
const parts = schemaPath.split("#");
79-
const filePath = parts[0];
80-
let schema: any;
81-
if (parts.length > 1) {
82-
schema = await this.loadSchema(filePath);
83-
schema = parts[1].split("/").filter(p => p).reduce((schema, key) => schema[key], schema);
77+
try {
78+
this.log("Loading", schemaPath);
79+
const parts = schemaPath.split("#");
80+
const filePath = parts[0];
81+
let schema: any;
82+
if (parts.length > 1) {
83+
schema = await this.loadSchema(filePath);
84+
schema = parts[1].split("/").filter(p => p).reduce((schema, key) => schema[key], schema);
85+
}
86+
else {
87+
const schemaContent = await readFile(filePath, 'utf-8');
88+
schema = filePath.endsWith(".json") ? JSON.parse(schemaContent) : YAML.parse(schemaContent);
89+
this.replaceRefs(filePath, schema);
90+
}
91+
this.schemata[schemaPath].schema = schema;
8492
}
85-
else {
86-
const schemaContent = await readFile(filePath, 'utf-8');
87-
schema = filePath.endsWith(".json") ? JSON.parse(schemaContent) : YAML.parse(schemaContent);
88-
this.replaceRefs(filePath, schema);
93+
catch (error) {
94+
console.error("Error occurred while loading schema", schemaPath, error);
95+
throw error;
8996
}
90-
this.schemata[schemaPath].schema = schema;
9197
}
9298

9399
private newPath(path: string): string {

0 commit comments

Comments
 (0)