diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index 1a95fd5474..c4e0e4fec9 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -93,7 +93,7 @@ impl SourceFileFetcher { Ok(file_fetcher) } - fn check_if_supported_scheme(url: &Url) -> Result<(), ErrBox> { + pub fn check_if_supported_scheme(url: &Url) -> Result<(), ErrBox> { if !SUPPORTED_URL_SCHEMES.contains(&url.scheme()) { return Err( OpError::other( diff --git a/cli/state.rs b/cli/state.rs index acf418189b..9fd719646c 100644 --- a/cli/state.rs +++ b/cli/state.rs @@ -1,5 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use crate::compilers::TargetLib; +use crate::file_fetcher::SourceFileFetcher; use crate::global_state::GlobalState; use crate::global_timer::GlobalTimer; use crate::import_map::ImportMap; @@ -474,6 +475,10 @@ impl State { module_specifier: &ModuleSpecifier, ) -> Result<(), OpError> { let u = module_specifier.as_url(); + // TODO(bartlomieju): temporary fix to prevent hitting `unreachable` + // statement that is actually reachable... + SourceFileFetcher::check_if_supported_scheme(u)?; + match u.scheme() { "http" | "https" => { self.check_net_url(u)?; diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index ff3777626c..b549dc6d09 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1583,6 +1583,13 @@ itest!(run_v8_help { output: "v8_help.out", }); +itest!(unsupported_dynamic_import_scheme { + args: "eval import('xxx:')", + output: "unsupported_dynamic_import_scheme.out", + check_stderr: true, + exit_code: 1, +}); + itest!(wasm { args: "run wasm.ts", output: "wasm.ts.out", diff --git a/cli/tests/unsupported_dynamic_import_scheme.out b/cli/tests/unsupported_dynamic_import_scheme.out new file mode 100644 index 0000000000..2a1a4e01f0 --- /dev/null +++ b/cli/tests/unsupported_dynamic_import_scheme.out @@ -0,0 +1,5 @@ +error: Uncaught TypeError: Unsupported scheme "xxx" for module "xxx:". Supported schemes: [ + "http", + "https", + "file", +]