Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node/module): More descriptive error in "createRequire" when invalid URL scheme is used #997

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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