From 12a59ada4d72ef694d2b1b9129f259f3e34c14e6 Mon Sep 17 00:00:00 2001 From: Andrey Nikitenko Date: Thu, 9 Apr 2015 15:34:44 +0300 Subject: [PATCH] Error message to be shown when formatting Error In case an Error to be formatted has a message, add it on top of the error stack. Sometimes error message is more useful than error stack, which is oftentimes doesn't have anything except when.js methods chain. --- lib/format.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/format.js b/lib/format.js index 6f93cd46..99c7517a 100644 --- a/lib/format.js +++ b/lib/format.js @@ -20,7 +20,8 @@ define(function() { */ function formatError(e) { var s = typeof e === 'object' && e !== null && e.stack ? e.stack : formatObject(e); - return e instanceof Error ? s : s + ' (WARNING: non-Error used)'; + var m = typeof e === 'object' && e !== null && e.message ? e.message + '\n' : ''; + return e instanceof Error ? m + s : s + ' (WARNING: non-Error used)'; } /**