deno icon indicating copy to clipboard operation
deno copied to clipboard

Deno panic when customizing `Error.prepareStackTrace`

Open kevgeoleo opened this issue 7 months ago • 2 comments

Version: Deno 2.3.3

Hi,

I would like to report a bug in Deno that causes panic. It can be reproduced by running the following code snippet. It worked on both Windows and MacOS.

class bar {
  constructor() {
    Error.prepareStackTrace = function (error, stack) {
      stack[0].getFileName();
      stack[1].getFileName();
      stack[2].getFileName();
    };
    this.stack = new Error("bar").stack;
  }
}

function foo() {
  throw new bar(() => message);
}

Object.defineProperty(Array.prototype, "0", {
  get: foo,
  set: foo,
});

x;    //node and bun throws Reference Error: x is not defined

kevgeoleo avatar May 21 '25 09:05 kevgeoleo

Adding the relevant panic:

file:///prooject/bar.mjs:161: Uncaught TypeError: Cannot read properties of undefined (reading 'getFileName')

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: macos aarch64
Version: 2.3.3
Args: ["deno", "bar.mjs"]

View stack trace at:
https://panic.deno.com/v2.3.3/aarch64-apple-darwin/4wyhKwkosqBgxi5qBwqi5qBwmv5qBo9-7Lgyp8Lw8_9Lwvl3P

thread 'main' panicked at /Users/admin/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/deno_core-0.347.0/error.rs:1260:55:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Stack trace:

View trace: here

marvinhagemeister avatar May 21 '25 09:05 marvinhagemeister

I will work on this!

edilson258 avatar May 25 '25 17:05 edilson258