Skip to content

Commit 2e9e001

Browse files
committed
Improve error handling in templateLoader by using Error constructor with message property
1 parent 73c6985 commit 2e9e001

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/templateLoader.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ function parseTemplateFile(filePath) {
1919
return parse(readFileSync(filePath, "utf8"));
2020
} catch (error) {
2121
if (error.code === "ENOENT") {
22-
throw Error(`Template file not found: ${filePath}`, error);
22+
throw new Error(`Template file not found: ${filePath}`, {message: error});
2323
} else if (error.name === "YAMLException") {
24-
throw Error("Invalid YAML in template file", error);
24+
throw new Error("Invalid YAML in template file", {message: error});
2525
} else if (error.name === "SyntaxError") {
26-
throw Error("Invalid JSON in template file", error);
26+
throw new Error("Invalid JSON in template file", {message: error});
2727
}
28-
throw Error("Error reading template file", error);
28+
throw new Error("Error reading template file", {message: error});
2929
}
3030
}
3131

@@ -43,7 +43,7 @@ async function dereferenceTemplates(templateDescriptions) {
4343
try {
4444
return await dereference(templateDescriptions);
4545
} catch (error) {
46-
throw Error("Failed to dereference template schemas", error);
46+
throw new Error("Failed to dereference template schemas", {message: error});
4747
}
4848
}
4949

@@ -61,7 +61,7 @@ function validateTemplates(templateDescriptions) {
6161
for (const templateName in templateDescriptions.templates) {
6262
const template = { [templateName]: templateDescriptions.templates[templateName] };
6363
if (!validateTemplate(template)) {
64-
throw Error("Template is invalid", { message: JSON.stringify(validateTemplate.errors) });
64+
throw new Error("Template is invalid", { message: JSON.stringify(validateTemplate.errors) });
6565
}
6666
}
6767

0 commit comments

Comments
 (0)