2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-10-18 13:36:28 -04:00
|
|
|
|
|
|
|
use deno_core::error::generic_error;
|
|
|
|
use deno_core::error::type_error;
|
|
|
|
use deno_core::error::AnyError;
|
|
|
|
use deno_core::url::Url;
|
|
|
|
|
2022-03-23 09:54:22 -04:00
|
|
|
pub fn err_invalid_module_specifier(
|
2021-10-18 13:36:28 -04:00
|
|
|
request: &str,
|
|
|
|
reason: &str,
|
|
|
|
maybe_base: Option<String>,
|
|
|
|
) -> AnyError {
|
|
|
|
let mut msg = format!(
|
|
|
|
"[ERR_INVALID_MODULE_SPECIFIER] Invalid module \"{}\" {}",
|
|
|
|
request, reason
|
|
|
|
);
|
|
|
|
|
|
|
|
if let Some(base) = maybe_base {
|
|
|
|
msg = format!("{} imported from {}", msg, base);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_error(msg)
|
|
|
|
}
|
|
|
|
|
2022-03-23 09:54:22 -04:00
|
|
|
pub fn err_module_not_found(path: &str, base: &str, typ: &str) -> AnyError {
|
2021-10-18 13:36:28 -04:00
|
|
|
generic_error(format!(
|
2021-11-24 10:55:10 -05:00
|
|
|
"[ERR_MODULE_NOT_FOUND] Cannot find {} \"{}\" imported from \"{}\"",
|
2021-10-18 13:36:28 -04:00
|
|
|
typ, path, base
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
2022-03-23 09:54:22 -04:00
|
|
|
pub fn err_unsupported_dir_import(path: &str, base: &str) -> AnyError {
|
2021-10-18 13:36:28 -04:00
|
|
|
generic_error(format!("[ERR_UNSUPPORTED_DIR_IMPORT] Directory import '{}' is not supported resolving ES modules imported from {}", path, base))
|
|
|
|
}
|
|
|
|
|
2022-03-23 09:54:22 -04:00
|
|
|
pub fn err_unsupported_esm_url_scheme(url: &Url) -> AnyError {
|
2021-10-18 13:36:28 -04:00
|
|
|
let mut msg =
|
|
|
|
"[ERR_UNSUPPORTED_ESM_URL_SCHEME] Only file and data URLS are supported by the default ESM loader"
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
if cfg!(window) && url.scheme().len() == 2 {
|
|
|
|
msg = format!(
|
|
|
|
"{}. On Windows, absolute path must be valid file:// URLs",
|
|
|
|
msg
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = format!("{}. Received protocol '{}'", msg, url.scheme());
|
|
|
|
generic_error(msg)
|
|
|
|
}
|