Closed Bug 1337103 Opened 7 years ago Closed 5 years ago

Console should iterate through asyncParent frames of a stack trace

Categories

(DevTools :: Console, defect, P3)

defect

Tracking

(firefox54 affected)

RESOLVED DUPLICATE of bug 1530843
Tracking Status
firefox54 --- affected

People

(Reporter: jryans, Unassigned)

References

(Blocks 1 open bug)

Details

The stack gathering code in the console actor appears to ignore asyncParents:

http://searchfox.org/mozilla-central/rev/f5077ad52f8b90183e73038869f6140f0afbf427/devtools/server/actors/webconsole.js#1506

There may also be other places in DevTools where we're dropping this extra data.  We should comb other places where we loop through stack frames.
This worked ok in the simple case I tried.
Do you know how I can get this to do the wrong thing?

webconsole.js instantiates a StackTraceCollector, which does handle
async parents nicely; but I don't see this actually being used in that file.

Also Console.cpp creates a sequence of ConsoleStackEntry objects, dealing
with async parents internally.  Though I also don't think the code in
preparePageErrorForRemote is dealing with these either, since it is using
|.parent| rather than iterating over some kind of container.
Flags: needinfo?(jryans)
(In reply to Tom Tromey :tromey from comment #1)
> This worked ok in the simple case I tried.
> Do you know how I can get this to do the wrong thing?

Here's an possible test case:

```
let bob = () => { setTimeout(function tom() { console.error(new Error()) }, 0) };
bob();
```

The console currently prints:

Error: 
Stack trace:
tom@debugger eval code:1:57

but it should be able to also list frames for the setTimeout and bob, if we traverse `asyncCaller`s.
 
> webconsole.js instantiates a StackTraceCollector, which does handle
> async parents nicely; but I don't see this actually being used in that file.

StackTraceCollector is used by the Net Monitor's tracking what triggered a request.  I think it's only appearing in webconsole.js because of the strange way that Net Monitor uses the console actors.

> Also Console.cpp creates a sequence of ConsoleStackEntry objects, dealing
> with async parents internally.  Though I also don't think the code in
> preparePageErrorForRemote is dealing with these either, since it is using
> |.parent| rather than iterating over some kind of container.

There appear to be many places we could be skipping this info, but it's a bit hard to search for:

http://searchfox.org/mozilla-central/search?q=.stack&case=true&regexp=false&path=devtools

As I understand it, here's an example of the correct looping to include this info:

http://searchfox.org/mozilla-central/rev/571c1fd0ba0617f83175ccc06ed6f3eb0a1a8b92/devtools/server/tests/unit/test_protocol_stack.js#85

One approach would be to centralize more of this into:

http://searchfox.org/mozilla-central/source/devtools/shared/platform/chrome/stack.js

which also seems to need updating.
Flags: needinfo?(jryans)
See Also: → 1459927
So, from the code linked before I don't think we look into asyncParent still, but the stacktrace shown for the code in Comment 2 do have the setTimeout information: 

tom         debugger eval code:1:47 
(Async: setTimeout handler) 
bob         debugger eval code:1:19 
<anonymous> debugger eval code:2:1

We should look at this more in detail to see if we have anything left to do or if we can close this.
Priority: -- → P3
Product: Firefox → DevTools
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → DUPLICATE
Blocks: dbg-captured
You need to log in before you can comment on or make changes to this bug.