mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix(cli/fmt_errors): Respect NO_COLOR for stack frames (#5051)
This commit is contained in:
parent
03d0ee60b4
commit
0f3e6e2eea
1 changed files with 12 additions and 4 deletions
|
@ -118,23 +118,31 @@ impl Deref for JSError {
|
|||
|
||||
impl fmt::Display for JSError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut formatted_frames = self.0.formatted_frames.clone();
|
||||
|
||||
// The formatted_frames passed from prepareStackTrace() are colored.
|
||||
if !colors::use_color() {
|
||||
formatted_frames = formatted_frames
|
||||
.iter()
|
||||
.map(|s| colors::strip_ansi_codes(s).to_string())
|
||||
.collect();
|
||||
}
|
||||
|
||||
// When the stack frame array is empty, but the source location given by
|
||||
// (script_resource_name, line_number, start_column + 1) exists, this is
|
||||
// likely a syntax error. For the sake of formatting we treat it like it was
|
||||
// given as a single stack frame.
|
||||
let formatted_frames = if self.0.formatted_frames.is_empty()
|
||||
if formatted_frames.is_empty()
|
||||
&& self.0.script_resource_name.is_some()
|
||||
&& self.0.line_number.is_some()
|
||||
&& self.0.start_column.is_some()
|
||||
{
|
||||
vec![format!(
|
||||
formatted_frames = vec![format!(
|
||||
"{}:{}:{}",
|
||||
colors::cyan(self.0.script_resource_name.clone().unwrap()),
|
||||
colors::yellow(self.0.line_number.unwrap().to_string()),
|
||||
colors::yellow((self.0.start_column.unwrap() + 1).to_string())
|
||||
)]
|
||||
} else {
|
||||
self.0.formatted_frames.clone()
|
||||
};
|
||||
|
||||
write!(
|
||||
|
|
Loading…
Add table
Reference in a new issue