Open Bug 1711887 Opened 3 years ago Updated 3 years ago

[META] Support Error Cause in DevTools

Categories

(DevTools :: General, task)

task

Tracking

(Not tracked)

People

(Reporter: nchevobbe, Unassigned)

References

Details

(Keywords: meta)

In Bug 1679653, the Error Cause proposal will be implemented (See https://github.com/tc39/proposal-error-cause)
This adds a new property to Error second parameter, cause:

new Error("oops", { cause })

The proposal is mostly targeted to re-throwing error with the ability to refers to the original error

try {
  thisMayThrow();
} catch(e) {
  throw new Error("it did throw", { cause: e })
}

but the cause can be any object.

In this bug, we should think of ways to display the cause when we're rendering an exception, as well as when logging an error object with a cause property.

Note that an exception might have a "tree" of causes:

a = () => { throw new Error("a") }
b = () => { 
  try {
    a();
  } catch(e) {
    throw new Error("issue when calling a", { cause: e });
  }
}
c = () => { 
  try {
    b();
  } catch(e) {
    throw new Error("issue when calling b", { cause: e });
  }
}
c();

In such case we might want to display:

Uncaught Error: issue when calling b
  c script:13
Cause: Uncaught Error: issue when calling a
  b script: 6
  c script:13
Cause: Uncaught Error: a
  a script: 1
  b script: 6
  c script:13

We should try to think of something so a given Cause block is visually linked to "its" error.
We also need to think of cases where the "Causes tree" would be too deep; do we want to display all causes? We might encounter cases with recursive functions creating long causes tree.

A question that may arise is if we should display or how we should display the stacktrace of "Cause" errors, as this might spam the console output.

Finally, we should be aware of cyclical causes, as the following could exist:

var a = new Error("a", {cause: b});
var b = new Error("b", {cause: a});
throw b;

Here it's not clear what should be rendered, maybe

Uncaught Error: b
  <anonymous> script:2
Cause: Uncaught Error: a
  <anonymous> script:1
Cause Uncaught Error: b <cyclical>

but in any case, that's something we should keep in mind when implementing this to avoid having infinite loop while retrieving the "Cause tree"

Depends on: 1712284
You need to log in before you can comment on or make changes to this bug.