3

When I rethrow an error, Safari 14.0.3 on macOS Big Sur doesn't print the entire (original) stacktrace. Instead it just points at the rethrow line.

Minimum reproducible example:

<!DOCTYPE html>
<html>
<head>
<script>
function one() {
  two();
}

function two() {
  three();
}

function three() {
  throw new Error('error from three');
}

try {
  one();
} catch (e) {
  console.log(e);
  throw e;
}
</script>
</head>
</html>

Running this in my browser Safari 14 prints

enter image description here

The actual error in the console from the line 21 rethrow, throw e;, only has a one-line stacktrace, pointing at this throw statement on line 21.

The real stacktrace is proven to exist on the error e by the log above, console.log(e) shows an entire stacktrace from one() to two() to three() to line 14 throw new Error...

This seems to be a Safari-only issue, none of Chrome, Firefox, nor Node.js have this problem.

Why doesn't Safari show the entire stacktrace of the rethrown error? How can I force it to do so?

In my in-development website I am doing a couple times:

try {
  coinToss();
} catch (e) {
  visuallyPresentErrorInWebpage(e);
  throw e;
}

I would love for the browser to automatically show me e's full stacktrace, how can I force it do that?

} catch (e) {
  visuallyPresentErrorInWebpage(e);
  console.error(e);
  throw e;
}

Is not ideal because now I have duplicated information in the console to slough through.

theonlygusti
  • 11,032
  • 11
  • 64
  • 119

0 Answers0