summaryrefslogtreecommitdiff
path: root/cli/fmt_errors.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-05-03 04:55:16 +0100
committerGitHub <noreply@github.com>2020-05-02 23:55:16 -0400
commit0f3e6e2eeaae882be83f5cb80388d0f4b183b474 (patch)
treef141aa5485efdb4c3fb80dba7a7ee2950fdd65d6 /cli/fmt_errors.rs
parent03d0ee60b40ce785276006e69a6040b5fc0c99d4 (diff)
fix(cli/fmt_errors): Respect NO_COLOR for stack frames (#5051)
Diffstat (limited to 'cli/fmt_errors.rs')
-rw-r--r--cli/fmt_errors.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs
index e0fc61459..7317d7fc0 100644
--- a/cli/fmt_errors.rs
+++ b/cli/fmt_errors.rs
@@ -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!(