refactor: centralize error handling with typed error classes - #24
Merged
Conversation
Replace scattered try/catch + console.error + process.exit patterns with a typed error hierarchy (CliError, ApiError, BapiError, PlapiError, UserAbortError) and a single top-level error handler in cli.ts. Commands now throw typed errors instead of handling exits locally, making error behavior consistent and testable. Adds --verbose flag for detailed API error output and SIGINT handling.
Add `context` field to `ApiError` and `withApiContext()` utility to attach human-readable operation context at call sites without verbose try/catch blocks. Drop internal "Platform API"/"Backend API" labels from the global error handler.
wyattjoh
force-pushed
the
wyattjoh/errors
branch
from
March 10, 2026 20:03
7a9189c to
ed9de03
Compare
Bun's test runner doesn't fully clear process.exitCode when set to undefined, causing the test file to exit with code 1 despite all assertions passing.
wyattjoh
marked this pull request as ready for review
March 10, 2026 20:19
brkalow
reviewed
Mar 11, 2026
| .action(deploy); | ||
|
|
||
| program.parse(); | ||
| function formatApiBody(body: string, verbose: boolean): string { |
Member
There was a problem hiding this comment.
consider making this a method on ApiError
brkalow
approved these changes
Mar 11, 2026
brkalow
left a comment
Member
There was a problem hiding this comment.
Looks good, do you think there are any meaningful additions to AGENTS.md to be made to ensure this pattern is followed?
jfoshee
reviewed
Mar 11, 2026
jfoshee
approved these changes
Mar 11, 2026
rafa-thayto
reviewed
Mar 11, 2026
…ndling - Rename usageError/userAbort to throwUsageError/throwUserAbort to make the never-returning throw behavior explicit at call sites - Auto-append .md to Clerk docs URLs in agent mode so agents receive raw markdown instead of rendered HTML
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
CliError,UserAbortError,ApiError,BapiError,PlapiError) insrc/lib/errors.tswith standardized exit codescli.tsthat catches all typed errors and formats output consistently--verboseflag for detailed API error outputSIGINThandler that exits with code 130.oxlintrc.json)Why
Error handling was scattered across every command — each had its own
try/catch+console.error+process.exitwith inconsistent formatting, exit codes, and messaging. This made it difficult to maintain consistent UX and meant every new command had to reimplement error handling. Centralizing it ensures uniform behavior and reduces per-command boilerplate.How
src/lib/errors.tswith a class hierarchy:CliErrorfor general CLI errors,ApiError(withBapiError/PlapiErrorsubclasses) for HTTP failures, andUserAbortErrorfor prompt cancellations. Helper functionsusageError()anduserAbort()provide ergonomic throwing.program.parseAsync()in amain()function with a centralizedcatchthat dispatches on error type — clean exit for aborts, red-formatted messages for CLI errors, labeled API error details for API failures.process.exit.AIE-626