Closed Bug 1530843 Opened 5 years ago Closed 4 years ago

Console actor drops asynchronous stacks from nsIConsoleService

Categories

(DevTools :: Console, defect, P2)

defect

Tracking

(firefox73 fixed)

RESOLVED FIXED
Firefox 73
Tracking Status
firefox73 --- fixed

People

(Reporter: jimb, Assigned: nchevobbe)

References

(Blocks 1 open bug)

Details

Attachments

(2 files, 1 obsolete file)

WebConsoleActor.prototype.preparePageErrorForRemote doesn't check stack frames' asyncParent property when transcribing the nsIScriptError's stack into an array for inclusion in the pageError packet sent to the client. The result is that stacks provided via the console service lack asynchronous callers when displayed in the console.

For example, evaluate the following in the console:

function a() {
  setTimeout(() => { throw new Error("bleah"); }, 2000);
}

function b() {
  a();
}

b();

The evaluation returns immediately; the result is undefined. Two seconds later, the setTimeout callback runs, and throws an exception. The exception is logged in the console with a stack that includes only the anonymous function in a, not a itself or its caller b.

The console learns about this uncaught exception via a listener it registered with nsIConsoleService. The stack attached to the error report includes the anonymous inner function, a, and b. However, since a is not the caller of the anonymous inner function, a is listed as its 'asynchronous caller': it appears as the anonymous function's stack frame's asyncParent property, while its parent property is null.

The preparePageErrorForRemote method is not aware of the asyncParent property, nor of the asyncCause property on the asynchronous caller frame, which explains by what mechanism the callee was dispatched (in the case above, it would be "setTimout handler"). It should follow asyncParent links, and include asyncCause values in the reported stacks.

Attached image better stack trace

The above is almost certainly not a complete fix; I assume there are other parts of the code that also walk stacks. But with that patch applied, I can get stack traces like this:

(In case that inline image doesn't work, it's just a link to the attachment.)

Thanks a lot Jim for looking into this.
Can I offer to write the test for this fix?

Flags: needinfo?(jimb)

Actually - would you be willing to take the bug altogether? :D

There may be other places in the code that need similar treatment.

Flags: needinfo?(jimb)

Sure :)
I'll look for other places

Assignee: nobody → nchevobbe
Status: NEW → ASSIGNED
Priority: -- → P2
Blocks: dbg-captured

Jim, would you happen the test case where you managed to get the async trace to work (Comment 2)?
I'm trying with the snippet from Comment 0 but I only get the last SavedFrame, and both asyncCause and asyncParent are null.
Does this need other patches?

Flags: needinfo?(jimb)

Huh, there should never be a truncated stack, given the code in comment 0. I had no further patches applied.

Comment 2 refers to Honza's test cases: https://outstanding-cowl.glitch.me/
referenced from the document here:
https://docs.google.com/document/d/1fEc8l0eXCflHH1qgRruoWU5i9WtpalKHwVgBxtHae7Y/edit#heading=h.gntwt77eq3hu

Flags: needinfo?(jimb)
Pushed by nchevobbe@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/8b7e877e3f6d
Check asyncParent when building message stacktrace in webconsole actor. r=Honza.
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 73
Attachment #9046858 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: