diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-02-02 01:58:53 -0500 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-02-02 17:33:21 -0500 |
commit | 4b61170e224344a94152ef6f618d6c71834e5cea (patch) | |
tree | d0a58d0a5a47c14be529621bea886d05863fb67b /src/js_errors.rs | |
parent | 98d20cd17894e02710a20425ba5ae8be52cfe932 (diff) |
Better error message for bad filename CLI argument.
Diffstat (limited to 'src/js_errors.rs')
-rw-r--r-- | src/js_errors.rs | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/js_errors.rs b/src/js_errors.rs index 73116d679..851d64be4 100644 --- a/src/js_errors.rs +++ b/src/js_errors.rs @@ -14,6 +14,7 @@ use source_map_mappings::parse_mappings; use source_map_mappings::Bias; use source_map_mappings::Mappings; use std::collections::HashMap; +use std::fmt; pub trait SourceMapGetter { /// Returns the raw source map file. @@ -73,39 +74,34 @@ impl ToString for StackFrame { } } -impl ToString for JSError { - fn to_string(&self) -> String { - // TODO Improve the formatting of these error messages. - let mut s = String::new(); - +impl fmt::Display for JSError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if self.script_resource_name.is_some() { let script_resource_name = self.script_resource_name.as_ref().unwrap(); // Avoid showing internal code from gen/bundle/main.js if script_resource_name != "gen/bundle/main.js" { - s.push_str(script_resource_name); + write!(f, "{}", script_resource_name)?; if self.line_number.is_some() { - s.push_str(&format!( + write!( + f, ":{}:{}", self.line_number.unwrap(), self.start_column.unwrap() - )); + )?; assert!(self.start_column.is_some()); } if self.source_line.is_some() { - s.push_str("\n"); - s.push_str(self.source_line.as_ref().unwrap()); - s.push_str("\n\n"); + write!(f, "\n{}\n\n", self.source_line.as_ref().unwrap())?; } } } - s.push_str(&self.message); + write!(f, "{}", &self.message)?; for frame in &self.frames { - s.push_str("\n"); - s.push_str(&frame.to_string()); + write!(f, "\n{}", &frame.to_string())?; } - s + Ok(()) } } |