diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-05-03 19:45:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-03 19:45:57 +0200 |
commit | 3f08a40412d89bd54222ad51fc1aaeb508e2e5e7 (patch) | |
tree | 61c8cac3376e4ef7f842dd3267bfd7ada31806c3 /core/error.rs | |
parent | 5ddb83a4c2a5622d0ea173c0798550ae76e1fd69 (diff) |
refactor: add core.formatLocationFilename, remove op_format_filename (#14474)
This commit moves "op_format_location" to "core/ops_builtin.rs"
and removes "Deno.core.createPrepareStackTrace" in favor of
"Deno.core.prepareStackTrace".
Co-authored-by: Aaron O'Mullan <aaron.omullan@gmail.com>
Diffstat (limited to 'core/error.rs')
-rw-r--r-- | core/error.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/core/error.rs b/core/error.rs index 8e6c43482..045dd5a15 100644 --- a/core/error.rs +++ b/core/error.rs @@ -2,6 +2,7 @@ use crate::runtime::JsRuntime; use crate::source_map::apply_source_map; +use crate::url::Url; use anyhow::Error; use std::borrow::Cow; use std::collections::HashMap; @@ -431,6 +432,27 @@ pub(crate) fn is_instance_of_error<'s>( false } +const DATA_URL_ABBREV_THRESHOLD: usize = 150; + +pub fn format_file_name(file_name: &str) -> String { + abbrev_file_name(file_name).unwrap_or_else(|| file_name.to_string()) +} + +fn abbrev_file_name(file_name: &str) -> Option<String> { + if file_name.len() <= DATA_URL_ABBREV_THRESHOLD { + return None; + } + let url = Url::parse(file_name).ok()?; + if url.scheme() != "data" { + return None; + } + let (head, tail) = url.path().split_once(',')?; + let len = tail.len(); + let start = tail.get(0..20)?; + let end = tail.get(len - 20..)?; + Some(format!("{}:{},{}......{}", url.scheme(), head, start, end)) +} + #[cfg(test)] mod tests { use super::*; |