Skip to content

runtime: expose Error static stack helpers and isError #2904

Description

@andrewtdiz

Summary

Node exposes V8-compatible static properties on Error: Error.captureStackTrace, Error.isError, Error.stackTraceLimit, and Error.prepareStackTrace. Perry implements Error object allocation and some stack formatting, but does not expose these static helpers/properties on the global Error constructor value.

Node behavior

Local Node v25.9.0:

console.log(typeof Error.captureStackTrace); // "function"
console.log(typeof Error.isError);           // "function"
console.log(Error.isError(new Error("x")));  // true
console.log(Error.isError({}));              // false
console.log(typeof Error.stackTraceLimit);   // "number"
console.log(typeof Error.prepareStackTrace); // "function"

const target = {};
Error.captureStackTrace(target);
console.log(typeof target.stack);            // "string"

These APIs are used by many Node libraries for custom error objects, stack hiding, error duck checks, and stack formatting configuration.

Perry evidence

  • Source search finds no Error.isError, js_error_is_error, captureStackTrace, stackTraceLimit, or prepareStackTrace implementation.
  • docs/typescript-parity-gaps.md still lists Error.captureStackTrace as missing.
  • crates/perry-runtime/src/error.rs implements Error allocation/stringification and native Error subclasses, but not the static constructor properties above.
  • crates/perry-runtime/src/object/global_this.rs exposes Error as a built-in constructor sentinel and installs Error.prototype.toString, but there is no static captureStackTrace, isError, stackTraceLimit, or prepareStackTrace property on that constructor.
  • crates/perry-codegen/src/expr/helpers.rs::is_global_this_builtin_name() treats Error as a global constructor value, but the first-class global constructor path currently does not provide these static members.

Expected behavior: expose the Node-compatible static Error surface, including Error.isError detection for Perry ErrorHeader values/subclasses, captureStackTrace(target[, constructorOpt]) writing a stack string onto arbitrary target objects, and readable/writable stack formatting controls where practical.

Related but not duplicate: #2836 tracks Error { cause } options, #2885 tracks EvalError/URIError construction, and #1278 / #616 covered stack frame format/prefix issues rather than these static properties.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions