Skip to content

Commit 7776636

Browse files
fix: support npm:bindings and npm:callsites packages (#24727)
Adds support for `npm:bindings` and `npm:callsites` packages because of changes in denoland/deno_core#838. This `deno_core` bump causes us to stop prepending `file://` scheme for locations in stack traces that are for local files. Fixes #24462 , fixes #22671 , fixes #15717 , fixes #19130 , fixes WiseLibs/better-sqlite3#1205 , fixes WiseLibs/better-sqlite3#1034 , fixes #20936 --------- Co-authored-by: Nathan Whitaker <[email protected]>
1 parent f4952f7 commit 7776636

File tree

4 files changed

+36
-102
lines changed

4 files changed

+36
-102
lines changed

Cargo.lock

+19-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ repository = "https://github.com/denoland/deno"
4545

4646
[workspace.dependencies]
4747
deno_ast = { version = "=0.40.0", features = ["transpiling"] }
48-
deno_core = { version = "0.298.0" }
48+
deno_core = { version = "0.299.0" }
4949

5050
deno_bench_util = { version = "0.156.0", path = "./bench_util" }
5151
deno_lockfile = "0.20.0"

cli/util/sync/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ mod task_queue;
66
mod value_creator;
77

88
pub use async_flag::AsyncFlag;
9+
pub use deno_core::unsync::sync::AtomicFlag;
910
pub use sync_read_async_write_lock::SyncReadAsyncWriteLock;
1011
pub use task_queue::TaskQueue;
1112
pub use task_queue::TaskQueuePermit;
1213
pub use value_creator::MultiRuntimeAsyncValueCreator;
13-
// todo(dsherret): this being in the unsync module is slightly confusing, but it's Sync
14-
pub use deno_core::unsync::AtomicFlag;

runtime/fmt_errors.rs

+15-90
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
22
//! This mod provides DenoError to unify errors across Deno.
3-
use deno_core::error::format_file_name;
3+
use deno_core::error::format_frame;
44
use deno_core::error::JsError;
5-
use deno_core::error::JsStackFrame;
65
use deno_terminal::colors::cyan;
76
use deno_terminal::colors::italic_bold;
87
use deno_terminal::colors::red;
@@ -21,96 +20,22 @@ struct IndexedErrorReference<'a> {
2120
index: usize,
2221
}
2322

24-
// Keep in sync with `/core/error.js`.
25-
pub fn format_location(frame: &JsStackFrame) -> String {
26-
let _internal = frame
27-
.file_name
28-
.as_ref()
29-
.map(|f| f.starts_with("ext:"))
30-
.unwrap_or(false);
31-
if frame.is_native {
32-
return cyan("native").to_string();
33-
}
34-
let mut result = String::new();
35-
let file_name = frame.file_name.clone().unwrap_or_default();
36-
if !file_name.is_empty() {
37-
result += &cyan(&format_file_name(&file_name)).to_string();
38-
} else {
39-
if frame.is_eval {
40-
result +=
41-
&(cyan(&frame.eval_origin.as_ref().unwrap()).to_string() + ", ");
42-
}
43-
result += &cyan("<anonymous>").to_string();
44-
}
45-
if let Some(line_number) = frame.line_number {
46-
write!(result, ":{}", yellow(&line_number.to_string())).unwrap();
47-
if let Some(column_number) = frame.column_number {
48-
write!(result, ":{}", yellow(&column_number.to_string())).unwrap();
49-
}
50-
}
51-
result
52-
}
53-
54-
fn format_frame(frame: &JsStackFrame) -> String {
55-
let _internal = frame
56-
.file_name
57-
.as_ref()
58-
.map(|f| f.starts_with("ext:"))
59-
.unwrap_or(false);
60-
let is_method_call =
61-
!(frame.is_top_level.unwrap_or_default() || frame.is_constructor);
62-
let mut result = String::new();
63-
if frame.is_async {
64-
result += "async ";
65-
}
66-
if frame.is_promise_all {
67-
result += &italic_bold(&format!(
68-
"Promise.all (index {})",
69-
frame.promise_index.unwrap_or_default()
70-
))
71-
.to_string();
72-
return result;
73-
}
74-
if is_method_call {
75-
let mut formatted_method = String::new();
76-
if let Some(function_name) = &frame.function_name {
77-
if let Some(type_name) = &frame.type_name {
78-
if !function_name.starts_with(type_name) {
79-
write!(formatted_method, "{type_name}.").unwrap();
80-
}
81-
}
82-
formatted_method += function_name;
83-
if let Some(method_name) = &frame.method_name {
84-
if !function_name.ends_with(method_name) {
85-
write!(formatted_method, " [as {method_name}]").unwrap();
86-
}
87-
}
88-
} else {
89-
if let Some(type_name) = &frame.type_name {
90-
write!(formatted_method, "{type_name}.").unwrap();
23+
struct AnsiColors;
24+
25+
impl deno_core::error::ErrorFormat for AnsiColors {
26+
fn fmt_element(
27+
element: deno_core::error::ErrorElement,
28+
s: &str,
29+
) -> std::borrow::Cow<'_, str> {
30+
use deno_core::error::ErrorElement::*;
31+
match element {
32+
Anonymous | NativeFrame | FileName | EvalOrigin => {
33+
cyan(s).to_string().into()
9134
}
92-
if let Some(method_name) = &frame.method_name {
93-
formatted_method += method_name
94-
} else {
95-
formatted_method += "<anonymous>";
96-
}
97-
}
98-
result += &italic_bold(&formatted_method).to_string();
99-
} else if frame.is_constructor {
100-
result += "new ";
101-
if let Some(function_name) = &frame.function_name {
102-
write!(result, "{}", italic_bold(&function_name)).unwrap();
103-
} else {
104-
result += &cyan("<anonymous>").to_string();
35+
LineNumber | ColumnNumber => yellow(s).to_string().into(),
36+
FunctionName | PromiseAll => italic_bold(s).to_string().into(),
10537
}
106-
} else if let Some(function_name) = &frame.function_name {
107-
result += &italic_bold(&function_name).to_string();
108-
} else {
109-
result += &format_location(frame);
110-
return result;
11138
}
112-
write!(result, " ({})", format_location(frame)).unwrap();
113-
result
11439
}
11540

11641
/// Take an optional source line and associated information to format it into
@@ -254,7 +179,7 @@ fn format_js_error_inner(
254179
0,
255180
));
256181
for frame in &js_error.frames {
257-
write!(s, "\n at {}", format_frame(frame)).unwrap();
182+
write!(s, "\n at {}", format_frame::<AnsiColors>(frame)).unwrap();
258183
}
259184
if let Some(cause) = &js_error.cause {
260185
let is_caused_by_circular = circular

0 commit comments

Comments
 (0)