Back to KB
Difficulty
Intermediate
Read Time
4 min

Inngest's instanceof lies: why custom error classes vanish across step.run

By Codcompass TeamΒ·Β·4 min read

Current Situation Analysis

In long-running, step-isolated pipelines (e.g., voice generation workflows chaining OpenAI β†’ ElevenLabs β†’ storage with consent gates), developers typically isolate vendor calls within step.run to prevent full pipeline replays on transient failures. Error classification relies heavily on custom error classes (TTSUpstreamError, TTSNotConfiguredError) and instanceof checks.

Pain Points & Failure Modes:

  • Silent Classification Failure: In production, every failed run defaults to elevenlabs_unknown, including actionable HTTP 402 responses that should trigger elevenlabs_upstream:402.
  • Broken Retry & Dashboard Logic: Downstream alerting, retry routing, and observability dashboards depend on precise error taxonomy. Silent fallbacks blind operators to vendor-specific degradation.
  • Why Traditional Methods Fail: instanceof relies on JavaScript prototype chain identity. Inngest's step.run memoizes step outcomes to enable deterministic replays. When a step fails, Inngest serializes the thrown error across the step boundary. Serialization strips the prototype chain, preserving only error.name, error.message, and optionally error.stack. By the time the catch block receives the error, it is a plain Error object with the correct shape but a broken prototype. Consequently, err instanceof TTSUpstreamError evaluates to false unconditionally in production.

WOW Moment: Key Findings

Experimental validation across dev, test, and production environments reveals a sharp divergence between in-process and cross-boundary error handling. The sweet spot emerges when shifting from prototype-based identity checks to shape-based matching combined with structured message parsing.

| Approach

πŸŽ‰ Mid-Year Sale β€” Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register β€” Start Free Trial

7-day free trial Β· Cancel anytime Β· 30-day money-back