fix: update message for unsupported schemes with npm and jsr (#26884)

Closes https://github.com/denoland/deno/issues/26596
This commit is contained in:
Bartek Iwańczuk 2024-11-15 17:09:19 +00:00 committed by GitHub
parent b8cf259924
commit dee94473c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 15 deletions

View file

@ -164,8 +164,19 @@ fn get_validated_scheme(
) -> Result<String, AnyError> {
let scheme = specifier.scheme();
if !SUPPORTED_SCHEMES.contains(&scheme) {
// NOTE(bartlomieju): this message list additional `npm` and `jsr` schemes, but they should actually be handled
// before `file_fetcher.rs` APIs are even hit.
let mut all_supported_schemes = SUPPORTED_SCHEMES.to_vec();
all_supported_schemes.extend_from_slice(&["npm", "jsr"]);
all_supported_schemes.sort();
let scheme_list = all_supported_schemes
.iter()
.map(|scheme| format!(" - \"{}\"", scheme))
.collect::<Vec<_>>()
.join("\n");
Err(generic_error(format!(
"Unsupported scheme \"{scheme}\" for module \"{specifier}\". Supported schemes: {SUPPORTED_SCHEMES:#?}"
"Unsupported scheme \"{scheme}\" for module \"{specifier}\". Supported schemes:\n{}",
scheme_list
)))
} else {
Ok(scheme.to_string())