diff options
-rw-r--r-- | cli/deno_error.rs | 2 | ||||
-rw-r--r-- | cli/tests/error_011_bad_module_specifier.ts.out | 2 | ||||
-rw-r--r-- | cli/tests/error_012_bad_dynamic_import_specifier.ts.out | 2 | ||||
-rw-r--r-- | cli/tests/error_014_catch_dynamic_import_error.js.out | 4 | ||||
-rw-r--r-- | cli/tests/error_type_definitions.ts.out | 2 | ||||
-rw-r--r-- | core/module_specifier.rs | 52 |
6 files changed, 46 insertions, 18 deletions
diff --git a/cli/deno_error.rs b/cli/deno_error.rs index 346149cd1..b16fb3fa6 100644 --- a/cli/deno_error.rs +++ b/cli/deno_error.rs @@ -140,7 +140,7 @@ impl GetErrorKind for ModuleResolutionError { match self { InvalidUrl(ref err) | InvalidBaseUrl(ref err) => err.kind(), InvalidPath(_) => ErrorKind::InvalidPath, - ImportPrefixMissing(_) => ErrorKind::ImportPrefixMissing, + ImportPrefixMissing(_, _) => ErrorKind::ImportPrefixMissing, } } } diff --git a/cli/tests/error_011_bad_module_specifier.ts.out b/cli/tests/error_011_bad_module_specifier.ts.out index 0a90cd32c..276443e5b 100644 --- a/cli/tests/error_011_bad_module_specifier.ts.out +++ b/cli/tests/error_011_bad_module_specifier.ts.out @@ -1,4 +1,4 @@ -[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../ +[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_011_bad_module_specifier.ts" [WILDCARD]dispatch_json.ts:[WILDCARD] at DenoError ([WILDCARD]errors.ts:[WILDCARD]) at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD]) diff --git a/cli/tests/error_012_bad_dynamic_import_specifier.ts.out b/cli/tests/error_012_bad_dynamic_import_specifier.ts.out index 0a90cd32c..52e5b913e 100644 --- a/cli/tests/error_012_bad_dynamic_import_specifier.ts.out +++ b/cli/tests/error_012_bad_dynamic_import_specifier.ts.out @@ -1,4 +1,4 @@ -[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../ +[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_012_bad_dynamic_import_specifier.ts" [WILDCARD]dispatch_json.ts:[WILDCARD] at DenoError ([WILDCARD]errors.ts:[WILDCARD]) at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD]) diff --git a/cli/tests/error_014_catch_dynamic_import_error.js.out b/cli/tests/error_014_catch_dynamic_import_error.js.out index c18b680a1..1a2ab2fd8 100644 --- a/cli/tests/error_014_catch_dynamic_import_error.js.out +++ b/cli/tests/error_014_catch_dynamic_import_error.js.out @@ -1,8 +1,8 @@ Caught direct dynamic import error. -TypeError: relative import path "does not exist" not prefixed with / or ./ or ../ +TypeError: relative import path "does not exist" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_014_catch_dynamic_import_error.js" Caught indirect direct dynamic import error. -TypeError: relative import path "does not exist either" not prefixed with / or ./ or ../ +TypeError: relative import path "does not exist either" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/indirect_import_error.js" Caught error thrown by dynamically imported module. Error: An error diff --git a/cli/tests/error_type_definitions.ts.out b/cli/tests/error_type_definitions.ts.out index d0b599862..e21b6d794 100644 --- a/cli/tests/error_type_definitions.ts.out +++ b/cli/tests/error_type_definitions.ts.out @@ -1,4 +1,4 @@ -[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "baz" not prefixed with / or ./ or ../ +[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "baz" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/type_definitions/bar.d.ts" [WILDCARD]dispatch_json.ts:[WILDCARD] at DenoError ([WILDCARD]errors.ts:[WILDCARD]) at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD]) diff --git a/core/module_specifier.rs b/core/module_specifier.rs index dbab0ce9b..ad24616ff 100644 --- a/core/module_specifier.rs +++ b/core/module_specifier.rs @@ -11,7 +11,7 @@ pub enum ModuleResolutionError { InvalidUrl(ParseError), InvalidBaseUrl(ParseError), InvalidPath(PathBuf), - ImportPrefixMissing(String), + ImportPrefixMissing(String, Option<String>), } use ModuleResolutionError::*; @@ -32,11 +32,19 @@ impl fmt::Display for ModuleResolutionError { write!(f, "invalid base URL for relative import: {}", err) } InvalidPath(ref path) => write!(f, "invalid module path: {:?}", path), - ImportPrefixMissing(ref specifier) => write!( - f, - "relative import path \"{}\" not prefixed with / or ./ or ../", - specifier - ), + ImportPrefixMissing(ref specifier, ref maybe_referrer) => { + let msg = format!( + "relative import path \"{}\" not prefixed with / or ./ or ../", + specifier + ); + let msg = if let Some(referrer) = maybe_referrer { + format!("{} Imported from \"{}\"", msg, referrer) + } else { + msg + }; + + write!(f, "{}", msg) + } } } } @@ -78,7 +86,12 @@ impl ModuleSpecifier { || specifier.starts_with("./") || specifier.starts_with("../")) => { - return Err(ImportPrefixMissing(specifier.to_string())) + let maybe_referrer = if base.is_empty() { + None + } else { + Some(base.to_string()) + }; + return Err(ImportPrefixMissing(specifier.to_string(), maybe_referrer)); } // 3. Return the result of applying the URL parser to specifier with base @@ -282,27 +295,42 @@ mod tests { ( "005_more_imports.ts", "http://deno.land/core/tests/006_url_imports.ts", - ImportPrefixMissing("005_more_imports.ts".to_string()), + ImportPrefixMissing( + "005_more_imports.ts".to_string(), + Some("http://deno.land/core/tests/006_url_imports.ts".to_string()), + ), ), ( ".tomato", "http://deno.land/core/tests/006_url_imports.ts", - ImportPrefixMissing(".tomato".to_string()), + ImportPrefixMissing( + ".tomato".to_string(), + Some("http://deno.land/core/tests/006_url_imports.ts".to_string()), + ), ), ( "..zucchini.mjs", "http://deno.land/core/tests/006_url_imports.ts", - ImportPrefixMissing("..zucchini.mjs".to_string()), + ImportPrefixMissing( + "..zucchini.mjs".to_string(), + Some("http://deno.land/core/tests/006_url_imports.ts".to_string()), + ), ), ( r".\yam.es", "http://deno.land/core/tests/006_url_imports.ts", - ImportPrefixMissing(r".\yam.es".to_string()), + ImportPrefixMissing( + r".\yam.es".to_string(), + Some("http://deno.land/core/tests/006_url_imports.ts".to_string()), + ), ), ( r"..\yam.es", "http://deno.land/core/tests/006_url_imports.ts", - ImportPrefixMissing(r"..\yam.es".to_string()), + ImportPrefixMissing( + r"..\yam.es".to_string(), + Some("http://deno.land/core/tests/006_url_imports.ts".to_string()), + ), ), ( "https://eggplant:b/c", |