{"record":{"id":"7178eff668b1f411","repo":"denoland/deno","slug":"invalidinput-7178ef","errorCode":"InvalidInput","errorMessage":"Can't convert url (\"{}\") to filename.","messagePattern":"Can't convert url \\(\"(.+?)\"\\) to filename\\.","errorType":"error_code","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"libs/cache_dir/cache.rs","lineNumber":99,"sourceCode":"        actual,\n      }))\n    } else {\n      Ok(())\n    }\n  }\n}\n\n/// Turn provided `url` into a hashed filename.\n/// URLs can contain a lot of characters that cannot be used\n/// in filenames (like \"?\", \"#\", \":\"), so in order to cache\n/// them properly they are deterministically hashed into ASCII\n/// strings.\npub fn url_to_filename(url: &Url) -> std::io::Result<PathBuf> {\n  // Replaces port part with a special string token (because\n  // \":\" cannot be used in filename on some platforms).\n  // Ex: $DENO_DIR/remote/https/deno.land/\n  let Some(cache_parts) = base_url_to_filename_parts(url) else {\n    return Err(std::io::Error::new(\n      ErrorKind::InvalidInput,\n      format!(\"Can't convert url (\\\"{}\\\") to filename.\", url),\n    ));\n  };\n\n  let rest_str = if let Some(query) = url.query() {\n    let mut rest_str =\n      String::with_capacity(url.path().len() + 1 + query.len());\n    rest_str.push_str(url.path());\n    rest_str.push('?');\n    rest_str.push_str(query);\n    Cow::Owned(rest_str)\n  } else {\n    Cow::Borrowed(url.path())\n  };\n\n  // NOTE: fragment is omitted on purpose - it's not taken into\n  // account when caching - it denotes parts of webpage, which","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/denoland/deno/blob/336da420f4343cbb1dcbd5eed9d075ff555ed6ee/libs/cache_dir/cache.rs#L81-L117","documentation":"libs/cache_dir's url_to_filename converts a remote-module URL into a cache file path by deriving parts from the URL's origin via base_url_to_filename_parts. URLs whose scheme/shape cannot be represented as cache paths (unsupported scheme, no host, etc.) yield None and this InvalidInput error, since the URL cannot map to a filesystem location.","triggerScenarios":"Calling local_path_for_url/get_cache_filename with a URL that has no base-encodable parts — e.g. non-http(s)/data-unsupported schemes (file:, blob:, custom schemes), URLs without a host, or malformed URLs accepted by the Url parser but not cacheable.","commonSituations":"Caching code fed blob: or file: URLs; tests passing synthetic URLs; custom loaders emitting non-remote URLs into the HTTP cache path; typos like htp:// in dynamically constructed URLs.","solutions":["Only pass remote http/https URLs to cache-path APIs; handle file:/blob: URLs with local-path logic instead.","Validate the URL scheme and host before requesting a cache filename.","Fix malformed/dynamically built URLs (missing host, wrong scheme).","Catch std::io::Error with ErrorKind::InvalidInput and fall back to a non-cache path."],"exampleFix":"// before\nlet path = get_cache_filename(&Url::parse(\"file:///local/mod.ts\")?).unwrap();\n// after\nlet url = Url::parse(\"https://deno.land/x/mod.ts\")?;\nif url.scheme().starts_with(\"http\") {\n  let path = get_cache_filename(&url)?;\n}","handlingStrategy":"try-catch","validationCode":"function isCacheable(u: URL): boolean {\n  return (u.protocol === \"https:\" || u.protocol === \"http:\") && u.hostname !== \"\";\n}","typeGuard":"function isRemoteHttpUrl(u: URL): u is URL {\n  return /^https?:$/.test(u.protocol) && u.hostname.length > 0;\n}","tryCatchPattern":"try {\n  const path = get_cache_filename(url);\n} catch (e) {\n  if (e instanceof Deno.errors.InvalidData || e.code === \"InvalidInput\") {\n    // non-cacheable URL: skip caching or handle via local loader\n  } else throw e;\n}","preventionTips":["Route file:/blob:/data: URLs to local-module handling, never the remote cache.","Validate scheme and host before cache-path conversion.","Fix URL construction bugs (missing host, typo'd schemes) at the source."],"tags":["cache","url","filesystem"],"backgroundTag":"invalid-url-format","analyzedSha":"336da420f4343cbb1dcbd5eed9d075ff555ed6ee","analyzedAt":"2026-09-11T17:12:50.272Z","contentChangedAt":"2026-09-11T17:12:50.272Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}