fix: add stackTraceLimit to ErrorConstructor interface and removed ErrorWithStackTraceLimit interface (#28539)

Signed-off-by: Jake Champion <me@jakechampion.name>
This commit is contained in:
Jake Champion 2025-03-18 13:56:39 +00:00 committed by GitHub
parent 1eaac23af8
commit 5aeb04f443
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 9 deletions

View file

@ -907,6 +907,7 @@ declare var CustomEvent: {
interface ErrorConstructor {
/** See https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions. */
captureStackTrace(error: Object, constructor?: Function): void;
stackTraceLimit: number;
// TODO(nayeemrmn): Support `Error.prepareStackTrace()`. We currently use this
// internally in a way that makes it unavailable for users.
}

View file

@ -373,10 +373,6 @@ export interface AssertionErrorConstructorOptions {
stackStartFunction?: Function;
}
interface ErrorWithStackTraceLimit extends ErrorConstructor {
stackTraceLimit: number;
}
export class AssertionError extends Error {
[key: string]: unknown;
@ -398,10 +394,8 @@ export class AssertionError extends Error {
expected,
} = options;
// TODO(schwarzkopfb): `stackTraceLimit` should be added to `ErrorConstructor` in
// cli/dts/lib.deno.shared_globals.d.ts
const limit = (Error as ErrorWithStackTraceLimit).stackTraceLimit;
(Error as ErrorWithStackTraceLimit).stackTraceLimit = 0;
const limit = Error.stackTraceLimit;
Error.stackTraceLimit = 0;
if (message != null) {
super(String(message));
@ -501,7 +495,7 @@ export class AssertionError extends Error {
}
}
(Error as ErrorWithStackTraceLimit).stackTraceLimit = limit;
Error.stackTraceLimit = limit;
this.generatedMessage = !message;
ObjectDefineProperty(this, "name", {