[DevTools] Format console.log(new Error()) same as console.log(new Error().stack) (issue 2284123002 by kozyatinskiy@chromium.org)

0 views
Skip to first unread message

kozyat...@chromium.org

unread,
Aug 26, 2016, 9:04:02 PM8/26/16
to lush...@chromium.org, chromium...@chromium.org, caseq...@chromium.org, lushnik...@chromium.org, pfeldma...@chromium.org, apavlo...@chromium.org, devtools...@chromium.org, blink-...@chromium.org, pfel...@chromium.org, kozyatins...@chromium.org
Reviewers: lushnikov
CL: https://codereview.chromium.org/2284123002/

Message:
Andrey, please take a look!

Description:
[DevTools] Format console.log(new Error()) same as console.log(new
Error().stack)

Then DevTools will linkify links from error.stack.

BUG=610559
R=lush...@chromium.org

Affected files (+54, -35 lines):
M third_party/WebKit/LayoutTests/inspector/console/console-log-linkify-stack-in-errors.html
M third_party/WebKit/LayoutTests/inspector/console/console-log-linkify-stack-in-errors-expected.txt
M third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js


Index: third_party/WebKit/LayoutTests/inspector/console/console-log-linkify-stack-in-errors-expected.txt
diff --git a/third_party/WebKit/LayoutTests/inspector/console/console-log-linkify-stack-in-errors-expected.txt b/third_party/WebKit/LayoutTests/inspector/console/console-log-linkify-stack-in-errors-expected.txt
index e80b3bb25bab2dba765f0ef13b9255a937b8e1cb..8275d16764e16cf0f830f8c1a4a26930063f5002 100644
--- a/third_party/WebKit/LayoutTests/inspector/console/console-log-linkify-stack-in-errors-expected.txt
+++ b/third_party/WebKit/LayoutTests/inspector/console/console-log-linkify-stack-in-errors-expected.txt
@@ -8,52 +8,53 @@ break
CONSOLE MESSAGE: line 30: TypeError: Cannot read property 'removeChild' of null
at domError (console-log-linkify-stack-in-errors.html:28:22)
at console-log-linkify-stack-in-errors.html:34:1
-CONSOLE MESSAGE: line 36: Error message without stacks http://www.chromium.org/
-CONSOLE MESSAGE: line 38: Error valid stack #2
+CONSOLE MESSAGE: line 41: Error: some error
+CONSOLE MESSAGE: line 47: Error message without stacks http://www.chromium.org/
+CONSOLE MESSAGE: line 49: Error valid stack #2
at http://www.chromium.org/boo.js:40:70
at foo(http://www.chromium.org/foo.js:10:50)
-CONSOLE MESSAGE: line 39: Error valid stack #3
+CONSOLE MESSAGE: line 50: Error valid stack #3
at http://www.chromium.org/foo.js:40
-CONSOLE MESSAGE: line 40: Error: MyError
+CONSOLE MESSAGE: line 51: Error: MyError
at throwError (http://www.chromium.org/foo.js:40)
at eval (eval at <anonymous> (http://www.chromium.org/foo.js:42:1), <anonymous>:1:1)
at http://www.chromium.org/foo.js:239
CONSOLE MESSAGE: line 20: ReferenceError: valid stack
at stack2 (console-log-linkify-stack-in-errors.html:20:21)
at stack1 (console-log-linkify-stack-in-errors.html:22:5)
- at console-log-linkify-stack-in-errors.html:42:1
+ at console-log-linkify-stack-in-errors.html:53:1
CONSOLE MESSAGE: line 20: EvalError: valid stack
at stack2 (console-log-linkify-stack-in-errors.html:20:21)
at stack1 (console-log-linkify-stack-in-errors.html:22:5)
- at console-log-linkify-stack-in-errors.html:43:1
+ at console-log-linkify-stack-in-errors.html:54:1
CONSOLE MESSAGE: line 20: SyntaxError: valid stack
at stack2 (console-log-linkify-stack-in-errors.html:20:21)
at stack1 (console-log-linkify-stack-in-errors.html:22:5)
- at console-log-linkify-stack-in-errors.html:44:1
+ at console-log-linkify-stack-in-errors.html:55:1
CONSOLE MESSAGE: line 20: RangeError: valid stack
at stack2 (console-log-linkify-stack-in-errors.html:20:21)
at stack1 (console-log-linkify-stack-in-errors.html:22:5)
- at console-log-linkify-stack-in-errors.html:45:1
+ at console-log-linkify-stack-in-errors.html:56:1
CONSOLE MESSAGE: line 20: TypeError: valid stack
at stack2 (console-log-linkify-stack-in-errors.html:20:21)
at stack1 (console-log-linkify-stack-in-errors.html:22:5)
- at console-log-linkify-stack-in-errors.html:46:1
+ at console-log-linkify-stack-in-errors.html:57:1
CONSOLE MESSAGE: line 20: URIError: valid stack
at stack2 (console-log-linkify-stack-in-errors.html:20:21)
at stack1 (console-log-linkify-stack-in-errors.html:22:5)
- at console-log-linkify-stack-in-errors.html:47:1
-CONSOLE MESSAGE: line 49: Error broken stack
+ at console-log-linkify-stack-in-errors.html:58:1
+CONSOLE MESSAGE: line 60: Error broken stack
at function_name(foob.js foob.js:30:1)
at foob.js:40:70
-CONSOLE MESSAGE: line 50: Error broken stack #2
+CONSOLE MESSAGE: line 61: Error broken stack #2
at function_name(foob.js:20:30
-CONSOLE MESSAGE: line 51: Error broken stack #3
+CONSOLE MESSAGE: line 62: Error broken stack #3
at function_name(foob:20.js:30 bla
-CONSOLE MESSAGE: line 52: Error broken stack #4
+CONSOLE MESSAGE: line 63: Error broken stack #4
at function_name)foob.js:20:30(
-CONSOLE MESSAGE: line 53: Error broken stack #5
+CONSOLE MESSAGE: line 64: Error broken stack #5
at function_name foob.js:20:30)
-CONSOLE MESSAGE: line 54: Error broken stack #6
+CONSOLE MESSAGE: line 65: Error broken stack #6
at foob.js foob.js:40:70
CONSOLE MESSAGE: line 9: Error
at Failure.letsFailWithStack (stack-with-sourceMap.js:19:20)
@@ -70,52 +71,55 @@ break
console-log-linkify-stack-in-errors.html:23 TypeError: Cannot read property 'removeChild' of null
at domError (console-log-linkify-stack-in-errors.html:21)
at console-log-linkify-stack-in-errors.html:27 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
-console-log-linkify-stack-in-errors.html:29 Error message without stacks http://www.chromium.org/ console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-external-link
-console-log-linkify-stack-in-errors.html:31 Error valid stack #2
+console-log-linkify-stack-in-errors.html:34 Error: some error
+ at logError (console-log-linkify-stack-in-errors.html:32)
+ at console-log-linkify-stack-in-errors.html:38 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
+console-log-linkify-stack-in-errors.html:40 Error message without stacks http://www.chromium.org/ console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-external-link
+console-log-linkify-stack-in-errors.html:42 Error valid stack #2
at www.chromium.org/boo.js:40
at foo(www.chromium.org/foo.js:10) console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
-console-log-linkify-stack-in-errors.html:32 Error valid stack #3
+console-log-linkify-stack-in-errors.html:43 Error valid stack #3
at www.chromium.org/foo.js:40 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link
-console-log-linkify-stack-in-errors.html:33 Error: MyError
+console-log-linkify-stack-in-errors.html:44 Error: MyError
at throwError (www.chromium.org/foo.js:40)
at eval (eval at <anonymous> (www.chromium.org/foo.js:42), <anonymous>:1:1)
at www.chromium.org/foo.js:239 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
console-log-linkify-stack-in-errors.html:13 ReferenceError: valid stack
at stack2 (console-log-linkify-stack-in-errors.html:13)
at stack1 (console-log-linkify-stack-in-errors.html:15)
- at console-log-linkify-stack-in-errors.html:35 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
+ at console-log-linkify-stack-in-errors.html:46 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
console-log-linkify-stack-in-errors.html:13 EvalError: valid stack
at stack2 (console-log-linkify-stack-in-errors.html:13)
at stack1 (console-log-linkify-stack-in-errors.html:15)
- at console-log-linkify-stack-in-errors.html:36 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
+ at console-log-linkify-stack-in-errors.html:47 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
console-log-linkify-stack-in-errors.html:13 SyntaxError: valid stack
at stack2 (console-log-linkify-stack-in-errors.html:13)
at stack1 (console-log-linkify-stack-in-errors.html:15)
- at console-log-linkify-stack-in-errors.html:37 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
+ at console-log-linkify-stack-in-errors.html:48 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
console-log-linkify-stack-in-errors.html:13 RangeError: valid stack
at stack2 (console-log-linkify-stack-in-errors.html:13)
at stack1 (console-log-linkify-stack-in-errors.html:15)
- at console-log-linkify-stack-in-errors.html:38 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
+ at console-log-linkify-stack-in-errors.html:49 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
console-log-linkify-stack-in-errors.html:13 TypeError: valid stack
at stack2 (console-log-linkify-stack-in-errors.html:13)
at stack1 (console-log-linkify-stack-in-errors.html:15)
- at console-log-linkify-stack-in-errors.html:39 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
+ at console-log-linkify-stack-in-errors.html:50 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
console-log-linkify-stack-in-errors.html:13 URIError: valid stack
at stack2 (console-log-linkify-stack-in-errors.html:13)
at stack1 (console-log-linkify-stack-in-errors.html:15)
- at console-log-linkify-stack-in-errors.html:40 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
-console-log-linkify-stack-in-errors.html:42 Error broken stack
+ at console-log-linkify-stack-in-errors.html:51 console-message-text source-code > console-message-url webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link > webkit-html-resource-link
+console-log-linkify-stack-in-errors.html:53 Error broken stack
at function_name(foob.js foob.js:30:1)
at foob.js:40:70 console-message-text source-code > console-message-url webkit-html-resource-link
-console-log-linkify-stack-in-errors.html:43 Error broken stack #2
+console-log-linkify-stack-in-errors.html:54 Error broken stack #2
at function_name(foob.js:20:30 console-message-text source-code > console-message-url webkit-html-resource-link
-console-log-linkify-stack-in-errors.html:44 Error broken stack #3
+console-log-linkify-stack-in-errors.html:55 Error broken stack #3
at function_name(foob:20.js:30 bla console-message-text source-code > console-message-url webkit-html-resource-link
-console-log-linkify-stack-in-errors.html:45 Error broken stack #4
+console-log-linkify-stack-in-errors.html:56 Error broken stack #4
at function_name)foob.js:20:30( console-message-text source-code > console-message-url webkit-html-resource-link
-console-log-linkify-stack-in-errors.html:46 Error broken stack #5
+console-log-linkify-stack-in-errors.html:57 Error broken stack #5
at function_name foob.js:20:30) console-message-text source-code > console-message-url webkit-html-resource-link
-console-log-linkify-stack-in-errors.html:47 Error broken stack #6
+console-log-linkify-stack-in-errors.html:58 Error broken stack #6
at foob.js foob.js:40:70 console-message-text source-code > console-message-url webkit-html-resource-link
stack-with-sourceMap.coffee:3 Error
at Failure.letsFailWithStack (stack-with-sourceMap.coffee:3)
Index: third_party/WebKit/LayoutTests/inspector/console/console-log-linkify-stack-in-errors.html
diff --git a/third_party/WebKit/LayoutTests/inspector/console/console-log-linkify-stack-in-errors.html b/third_party/WebKit/LayoutTests/inspector/console/console-log-linkify-stack-in-errors.html
index 38ee441d287ee1a4bb40b51a99d3655cbd0f15ad..0d9e044f00d2a4ec6bd3e83daef0c93af45fe347 100644
--- a/third_party/WebKit/LayoutTests/inspector/console/console-log-linkify-stack-in-errors.html
+++ b/third_party/WebKit/LayoutTests/inspector/console/console-log-linkify-stack-in-errors.html
@@ -33,6 +33,17 @@ function domError()

domError();

+function logError()
+{
+ try {
+ throw new Error("some error");
+ } catch (e) {
+ console.log(e);
+ }
+}
+
+logError();
+
console.log("Error message without stacks http://www.chromium.org/");

console.log("Error valid stack #2\n at http://www.chromium.org/boo.js:40:70\n at foo(http://www.chromium.org/foo.js:10:50)");
Index: third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js
diff --git a/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js b/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js
index 68fb24cbe1c6b2e8f8f597c8958cbbe543b55c00..f4215455af47eee30d55c08123714f1658dc1948 100644
--- a/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js
+++ b/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js
@@ -178,9 +178,13 @@ WebInspector.ConsoleViewMessage.prototype = {
this._messageElement = this._format([consoleMessage.messageText]);
break;
default:
- if (consoleMessage.parameters && consoleMessage.parameters.length === 1 && consoleMessage.parameters[0].type === "string")
- this._messageElement = this._tryFormatAsError(/** @type {string} */(consoleMessage.parameters[0].value));
-
+ if (consoleMessage.parameters && consoleMessage.parameters.length === 1) {
+ var firstArg = consoleMessage.parameters[0];
+ if (firstArg.type === "string")
+ this._messageElement = this._tryFormatAsError(/** @type {string} */(firstArg.value));
+ else if (firstArg.type === "object" && firstArg.subtype === "error" && firstArg.description)
+ this._messageElement = this._tryFormatAsError(firstArg.description);
+ }
var args = consoleMessage.parameters || [consoleMessage.messageText];
this._messageElement = this._messageElement || this._format(args);
}


kozyat...@chromium.org

unread,
Aug 26, 2016, 10:02:56 PM8/26/16
to lush...@chromium.org, chromium...@chromium.org, caseq...@chromium.org, lushnik...@chromium.org, pfeldma...@chromium.org, apavlo...@chromium.org, devtools...@chromium.org, blink-...@chromium.org, pfel...@chromium.org, kozyatins...@chromium.org
Andrey, it's ready for review, please take another look!

https://codereview.chromium.org/2284123002/

lush...@chromium.org

unread,
Aug 29, 2016, 6:00:37 PM8/29/16
to kozyat...@chromium.org, chromium...@chromium.org, caseq...@chromium.org, lushnik...@chromium.org, pfeldma...@chromium.org, apavlo...@chromium.org, devtools...@chromium.org, blink-...@chromium.org, pfel...@chromium.org, kozyatins...@chromium.org
can you please attach a screenshot of visual changes? (there are some, right?)

https://codereview.chromium.org/2284123002/

lush...@chromium.org

unread,
Aug 29, 2016, 6:05:28 PM8/29/16
to kozyat...@chromium.org, chromium...@chromium.org, caseq...@chromium.org, lushnik...@chromium.org, pfeldma...@chromium.org, apavlo...@chromium.org, devtools...@chromium.org, blink-...@chromium.org, pfel...@chromium.org, kozyatins...@chromium.org
lgtm


https://codereview.chromium.org/2284123002/diff/20001/third_party/WebKit/LayoutTests/inspector/console/console-save-to-temp-var-expected.txt
File
third_party/WebKit/LayoutTests/inspector/console/console-save-to-temp-var-expected.txt
(right):

https://codereview.chromium.org/2284123002/diff/20001/third_party/WebKit/LayoutTests/inspector/console/console-save-to-temp-var-expected.txt#newcode27
third_party/WebKit/LayoutTests/inspector/console/console-save-to-temp-var-expected.txt:27:
Error: errr
is there no stack at all?

https://codereview.chromium.org/2284123002/diff/20001/third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/debugger-eval-while-paused-throws.html
File
third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/debugger-eval-while-paused-throws.html
(right):

https://codereview.chromium.org/2284123002/diff/20001/third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/debugger-eval-while-paused-throws.html#newcode75
third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/debugger-eval-while-paused-throws.html:75:
//# sourceURL=test.js
why this change? is this a beautification?

https://codereview.chromium.org/2284123002/

kozyat...@chromium.org

unread,
Aug 29, 2016, 9:19:33 PM8/29/16
to lush...@chromium.org, chromium...@chromium.org, caseq...@chromium.org, lushnik...@chromium.org, pfeldma...@chromium.org, apavlo...@chromium.org, devtools...@chromium.org, blink-...@chromium.org, pfel...@chromium.org, kozyatins...@chromium.org

https://codereview.chromium.org/2284123002/diff/20001/third_party/WebKit/LayoutTests/inspector/console/console-save-to-temp-var-expected.txt
File
third_party/WebKit/LayoutTests/inspector/console/console-save-to-temp-var-expected.txt
(right):

https://codereview.chromium.org/2284123002/diff/20001/third_party/WebKit/LayoutTests/inspector/console/console-save-to-temp-var-expected.txt#newcode27
third_party/WebKit/LayoutTests/inspector/console/console-save-to-temp-var-expected.txt:27:
Error: errr
On 2016/08/29 22:05:21, lushnikov wrote:
> is there no stack at all?

yes, no Error.stack at all.


https://codereview.chromium.org/2284123002/diff/20001/third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/debugger-eval-while-paused-throws.html
File
third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/debugger-eval-while-paused-throws.html
(right):

https://codereview.chromium.org/2284123002/diff/20001/third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/debugger-eval-while-paused-throws.html#newcode75
third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/debugger-eval-while-paused-throws.html:75:
//# sourceURL=test.js
On 2016/08/29 22:05:21, lushnikov wrote:
> why this change? is this a beautification?

It's beautification, otherwise scripts from this test will get path that
contains user dir.

https://codereview.chromium.org/2284123002/

commit-bot@chromium.org via codereview.chromium.org

unread,
Aug 29, 2016, 11:49:04 PM8/29/16
to kozyat...@chromium.org, lush...@chromium.org, commi...@chromium.org, chromium...@chromium.org, caseq...@chromium.org, lushnik...@chromium.org, pfeldma...@chromium.org, apavlo...@chromium.org, devtools...@chromium.org, blink-...@chromium.org, pfel...@chromium.org, kozyatins...@chromium.org

commit-bot@chromium.org via codereview.chromium.org

unread,
Aug 30, 2016, 1:17:59 AM8/30/16
to kozyat...@chromium.org, lush...@chromium.org, commi...@chromium.org, chromium...@chromium.org, caseq...@chromium.org, lushnik...@chromium.org, pfeldma...@chromium.org, apavlo...@chromium.org, devtools...@chromium.org, blink-...@chromium.org, pfel...@chromium.org, kozyatins...@chromium.org
Committed patchset #2 (id:20001)

https://codereview.chromium.org/2284123002/

commit-bot@chromium.org via codereview.chromium.org

unread,
Aug 30, 2016, 1:20:12 AM8/30/16
to kozyat...@chromium.org, lush...@chromium.org, commi...@chromium.org, chromium...@chromium.org, caseq...@chromium.org, lushnik...@chromium.org, pfeldma...@chromium.org, apavlo...@chromium.org, devtools...@chromium.org, blink-...@chromium.org, pfel...@chromium.org, kozyatins...@chromium.org
Patchset 2 (id:??) landed as
https://crrev.com/cdcbb06b51d195d106b4a217a6fa411fd8b54a66
Cr-Commit-Position: refs/heads/master@{#415145}

https://codereview.chromium.org/2284123002/
Reply all
Reply to author
Forward
0 new messages