Skip to content

Commit

Permalink
fix(node/module): More descriptive error in "createRequire" (#997)
Browse files Browse the repository at this point in the history
  • Loading branch information
TotallyNotChase committed Jul 2, 2021
1 parent f4496b7 commit 1914407
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion node/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,21 @@ class Module {
filename instanceof URL ||
(typeof filename === "string" && !path.isAbsolute(filename))
) {
filepath = fileURLToPath(filename);
try {
filepath = fileURLToPath(filename);
} catch (err) {
if (
err instanceof Deno.errors.InvalidData &&
err.message.includes("invalid url scheme")
) {
// Provide a descriptive error when url scheme is invalid.
throw new Error(
`${createRequire.name} only supports 'file://' URLs for the 'filename' parameter`,
);
} else {
throw err;
}
}
} else if (typeof filename !== "string") {
throw new Error("filename should be a string");
} else {
Expand Down

0 comments on commit 1914407

Please sign in to comment.