Skip to content

Commit

Permalink
fix: clearer error message when user scripts are preventing templates…
Browse files Browse the repository at this point in the history
… from executing

refs: #1212
  • Loading branch information
Zachatoo committed Oct 3, 2023
1 parent 71f48e2 commit 0cb0202
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/functions/user_functions/UserScriptFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,24 @@ export class UserScriptFunctions implements IGenerateObject {
file_content +
"\n})"
);
wrapping_fn(req, mod, exp);
try {
wrapping_fn(req, mod, exp);
} catch (err) {
throw new TemplaterError(
`Failed to load user script at "${file.path}".`,
err.message
);
}
const user_function = exp["default"] || mod.exports;

if (!user_function) {
throw new TemplaterError(
`Failed to load user script ${file.path}. No exports detected.`
`Failed to load user script at "${file.path}". No exports detected.`
);
}
if (!(user_function instanceof Function)) {
throw new TemplaterError(
`Failed to load user script ${file.path}. Default export is not a function.`
`Failed to load user script at "${file.path}". Default export is not a function.`
);
}
user_script_functions.set(
Expand Down

0 comments on commit 0cb0202

Please sign in to comment.