stack from console.error with Error objects

112 visningar
Hoppa till det första olästa meddelandet

johnjbarton

oläst,
6 nov. 2011 18:14:322011-11-06
till google-chrome-...@googlegroups.com
One of the most frustrating issues I have with Web Inspector is the representations of Error objects. I have a habit of writing:
   console.error("MethodName <something> FAILED "+exc, exc);
This way I get a quick string error message. I don't recognize the problem  I can expand the object in the Console to examine the call stack.

But this does not work on Web Inspector because I can't get the call stack: the stack property is a getter.   Is there some solution to this that I don't know? Of course I can put code in front of every console log call to test if the object has a stack, and if so grab it, parse into lines, and put it back on the object. But that is a lot work and still no links to source.

jjb

pfeldman

oläst,
8 nov. 2011 01:58:112011-11-08
till Google Chrome Developer Tools
(Disclaimer: Error.stack is a string, so "parsing into lines" is not
going away).

This is only a problem when inspector front-end is closed at the
moment of the logging. Otherwise, console.error entry itself expands
into the structured stack. Few ways we could address the problem
though:

1) In the object tree views, allow getter evaluation (hover over a
getter to get a small "evaluate" link that shows you the actual
value). Is probably worth doing in either case
2) For Error objects with stacks, render additional property
"stackTrace" with structural stack info. Is a hack, but is probably
worth doing

What do you think?

Regards
Pavel

John J Barton

oläst,
8 nov. 2011 11:51:192011-11-08
till pfeldman, Google Chrome Developer Tools
On Mon, Nov 7, 2011 at 10:58 PM, pfeldman <pfel...@chromium.org> wrote:
> (Disclaimer: Error.stack is a string, so "parsing into lines" is not
> going away).
>
> This is only a problem when inspector front-end is closed at the
> moment of the logging. Otherwise, console.error entry itself expands
> into the structured stack. Few ways we could address the problem
> though:
>
> 1) In the object tree views, allow getter evaluation (hover over a
> getter to get a small "evaluate" link that shows you the actual
> value). Is probably worth doing in either case

Yes, since from the caller's point of view a getter is a value (with
typically only idempotent side effects) the dev will want to see the
result. I suppose this can be a problem for mis-designed getters.

I assume this can be lazy? ie no rendering until the dev hovers?

> 2) For Error objects with stacks, render additional property
> "stackTrace" with structural stack info. Is a hack, but is probably
> worth doing

Is there a way to do this lazily, ie do not render until the dev
clicks on the log message? The stack can be 3000 x 100 bytes and 1000
log messages means 300M. Ok that's rare but it could be a performance
hit, which why I guess the getter was there in the first place.

Another idea would be an additional property "shortTrace" with 5
frames from the oldest and newest ends of the trace around a single
line telling how many frames are omitted. I think this would solve the
vast majority of the cases where we want to browse the stack.
Combined with the hover on getter we'd have a good combo.

jjb

Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden