Skip to content

Error subclass loses cause when forwarding options via super(message, options) #5127

Description

@proggeramlug

Perry version: origin/main @ a674b6e (v0.5.1167)
Platform: macOS arm64 (Darwin 25.5)
Build/run: perry repro.ts -o out && ./out
Baseline: node --experimental-strip-types repro.ts

(Found via an internal worst-case stress suite.)

Bug

A subclass of Error that forwards options via super(message, options) loses the causethis.cause is undefined afterward. A plain new Error(msg, { cause }) (no subclass) works, so the option is dropped specifically when passed up through super(...).

Repro

class AppError extends Error {
  constructor(msg: string, opts?: ErrorOptions) { super(msg, opts); this.name = "AppError"; }
}
const e = new AppError("high-level", { cause: new TypeError("low-level") });
console.log(e.message, (e.cause as Error)?.message);

Expected (Node)

high-level low-level

Actual (Perry)

high-level undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed defect or regressionparityCompatibility gap with Node.js, ECMAScript, or the supported ecosystem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions