Skip to content

[BUG] errors.ts error class hierarchy doesn't preserve the instanceof relationship after being caught across a Promise boundary bundled by some bundlers #806

Open

Description

@meshackyaro

Description

Custom error subclasses (e.g. EscrowError extends TrustFlowError) can fail instanceof checks after passing through certain bundler/transpilation configurations (notably targeting older JS targets) that don't correctly handle extending built-in Error.

Component

core

Steps to Reproduce

  1. Build a consuming app targeting an older JS target (e.g. ES5) using a bundler known to have this issue with native class extension.
  2. Catch a EscrowError thrown by the SDK.
  3. Check error instanceof EscrowError and error instanceof TrustFlowError.

Expected Behavior

Custom error classes should reliably support instanceof checks regardless of the consuming app's build target, typically by following the documented workaround pattern for extending Error in TypeScript/Babel.

Actual Behavior

instanceof checks unexpectedly return false for errors that genuinely are instances of the expected class, breaking any error-type-based handling logic in the consuming app.

Environment

  • SDK version: 0.3.x
  • Node version: 20.x, 22.x
  • OS: macOS / Linux
  • Network: TESTNET

Code Example

try {
  await createEscrow(client, badParams);
} catch (e) {
  if (e instanceof EscrowError) { /* never reached in some build configs */ }
}

Error Output

N/A — no thrown error; behavior is incorrect but silent.

Difficulty

🟡 Medium

Additional Context

The error classes extend Error without the Object.setPrototypeOf workaround needed for compatibility with ES5-targeting transpilation.

Activity

  1. added
    bug
    difficulty: medium
    priority: medium
    on Oct 29, 2026
  2. ranjeet150 commented on Oct 29, 2026

    @ranjeet150

    Hello,

    I am interested in taking up "[BUG] errors.ts error class hierarchy doesn't preserve the instanceof relationship after being caught across a Promise boundary bundled by some bundlers" and implementing a production-grade solution.

    I have reviewed the problem description and acceptance criteria for this issue. I have a clear, tested implementation ready with defensive error handling and 100% green CI proof.

    I will deliver a clean, well-tested, and production-ready PR promptly upon assignment. Kindly assign this issue to me.

    Thank you!

  3. ranjan1969x commented on Nov 8, 2026

    @ranjan1969x

    Hi everyone,

    I reviewed the requirements for errors.ts error class hierarchy doesn't preserve the instanceof relationship after being caught across a Promise boundary bundled by some bundlers. Looking into the issue, we need to resolve 'errors.ts error class hierarchy doesn't preserve the instanceof relationship after being caught across a Promise boundary bundled by some bundlers' cleanly across the target modules. My plan is to trace the current code execution path in errors.ts to isolate the behavior boundary, implement a focused, modular fix for 'errors.ts error class hierarchy doesn't preserve the instanceof relationship after being caught across a promise boundary bundled by some bundlers' adhering strictly to repository architecture, and ensure ensure defensive guards and backward compatibility are maintained.

    For testing, I'll reproduce the target scenario locally, add regression unit tests, and confirm all CI checks pass 100% green.

    Happy to take this on. Please assign it over and I'll get the PR ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcoredifficulty: mediumpriority: mediumsdk

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions