From 986ad08bce7781e17f98d17d223033a2eb0785af Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Thu, 8 Oct 2020 10:05:19 +0100 Subject: fix(cli/rt/error_stack): Improve message line formatting (#7860) --- core/error.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'core/error.rs') diff --git a/core/error.rs b/core/error.rs index 1aa67e26c..30aa88773 100644 --- a/core/error.rs +++ b/core/error.rs @@ -174,14 +174,24 @@ impl JsError { // Get the message by formatting error.name and error.message. let name = get_property(scope, exception, "name") + .filter(|v| !v.is_undefined()) .and_then(|m| m.to_string(scope)) .map(|s| s.to_rust_string_lossy(scope)) - .unwrap_or_else(|| "undefined".to_string()); + .unwrap_or_else(|| "Error".to_string()); let message_prop = get_property(scope, exception, "message") + .filter(|v| !v.is_undefined()) .and_then(|m| m.to_string(scope)) .map(|s| s.to_rust_string_lossy(scope)) - .unwrap_or_else(|| "undefined".to_string()); - let message = format!("Uncaught {}: {}", name, message_prop); + .unwrap_or_else(|| "".to_string()); + let message = if name != "" && message_prop != "" { + format!("Uncaught {}: {}", name, message_prop) + } else if name != "" { + format!("Uncaught {}", name) + } else if message_prop != "" { + format!("Uncaught {}", message_prop) + } else { + "Uncaught".to_string() + }; // Access error.stack to ensure that prepareStackTrace() has been called. // This should populate error.__callSiteEvals. -- cgit v1.2.3