Skip to content

refactor: unify error constructors to object params, add validationErrors - #1

Merged
priosshrsth merged 2 commits into
mainfrom
refactor/error-object-params
Mar 1, 2026
Merged

refactor: unify error constructors to object params, add validationErrors#1
priosshrsth merged 2 commits into
mainfrom
refactor/error-object-params

Conversation

@priosshrsth

Copy link
Copy Markdown
Collaborator

Summary

  • Replace inconsistent positional constructor params across all error subclasses with a single uniform object { message?, cause?, details? }
  • AssemblyResponseParseError narrows cause to ZodError (required) and drops the old zodError field — access via .cause
  • Add validationErrors: string property using z.prettifyError() (Zod 4 built-in) for human-readable issue output
  • Export all option interfaces (AssemblyErrorOptions, AssemblyRateLimitErrorOptions, AssemblyResponseParseErrorOptions) from the public index

Before / After

Before (inconsistent positional params):

new AssemblyConnectionError("custom msg", { raw: "body" })
new AssemblyRateLimitError("slow down", 30, details)      // retryAfter sandwiched in
new AssemblyResponseParseError(zodError, "custom msg")    // args reversed

After (uniform object):

new AssemblyConnectionError({ message: "custom msg", details: { raw: "body" } })
new AssemblyRateLimitError({ message: "slow down", retryAfter: 30 })
new AssemblyResponseParseError({ cause: zodError, message: "custom msg" })

// readable validation output
err.validationErrors
// ✖ Invalid input: expected string, received number
//   → at user.name
// ✖ Invalid email address
//   → at user.email

Test plan

  • bun test — all 68 tests pass
  • bun run type-check — no type errors
  • bun run lint — no lint errors

🤖 Generated with Claude Code

priosshrsth and others added 2 commits March 1, 2026 10:02
…rors

Replace inconsistent positional params (messageOverride, details, retryAfter)
with a uniform single-object signature { message?, cause?, details? } on all
error subclasses. AssemblyResponseParseError narrows cause to ZodError and
exposes validationErrors (z.prettifyError output) for human-readable output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ions

- AssemblyResponseParseError: replace `declare readonly cause: ZodError`
  (pure type assertion with no runtime presence) with an `override get cause()`
  getter that casts at the point of use — explicit, transparent, and safe
- Destructure cause/details individually in the constructor instead of spreading
  ...rest, making the parameter flow explicit
- Add JSDoc to AssemblyErrorOptions fields clarifying the message/cause/details
  contract and the optional-vs-required split between the public interface and
  the internal AssemblyBaseErrorInit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@priosshrsth
priosshrsth merged commit d2cf2c4 into main Mar 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant