Skip to content

refactor(cli): convert modify.ts and add.ts to typed error flow#281

Open
galligan wants to merge 2 commits into
outfitter/v2-core-resultsfrom
outfitter/v2-cli-handlers
Open

refactor(cli): convert modify.ts and add.ts to typed error flow#281
galligan wants to merge 2 commits into
outfitter/v2-core-resultsfrom
outfitter/v2-cli-handlers

Conversation

@galligan

@galligan galligan commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

refactor(cli): convert modify.ts and add.ts to typed error flow

Replace throw new Error(...) with typed contract errors
(ValidationError, NotFoundError) in modify and add command handlers.
Update Result.tryPromise catch handlers to preserve error category
instead of wrapping all errors as InternalError.

🤘🏻 In-collaboration-with: Claude Code

refactor(cli): convert remaining CLI handlers to typed error flow

Convert throws in init.ts, remove.ts, scan.ts, update.ts, fmt.ts,
lint.ts, check.ts, and doctor.ts to use typed contract errors
(ValidationError, InternalError) instead of generic Error. Update all
Result.tryPromise catch handlers to preserve error categories via
AnyKitError duck-typing.

🤘🏻 In-collaboration-with: Claude Code

Greptile Summary

Refactored CLI command handlers to use typed error flow instead of generic Error throws. Replaced throw new Error(...) with ValidationError, NotFoundError, and InternalError from @outfitter/contracts. Updated all Result.tryPromise catch handlers to preserve error categories using duck-typing pattern ("category" in cause) instead of wrapping everything as InternalError.

Key changes across 10 files:

  • Validation errors now use ValidationError.fromMessage() or ValidationError.create(field, message)
  • Not-found scenarios use NotFoundError.create(type, identifier, context?)
  • Result handlers check for "category" property to preserve typed errors
  • Return types changed from Result<T, InternalError> to Result<T, AnyKitError>

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The refactoring consistently applies a well-defined pattern across all files. The changes are purely error handling improvements that preserve existing behavior while adding type safety. All modified code follows the same duck-typing pattern for error category preservation, and the conversion from generic errors to typed errors is straightforward and correct.
  • No files require special attention

Important Files Changed

Filename Overview
packages/cli/src/commands/add.ts Converted from generic Error to typed ValidationError, preserved error categories in Result.tryPromise catch handler using duck-typing pattern
packages/cli/src/commands/modify.ts Converted to typed ValidationError and NotFoundError, updated Result.tryPromise to preserve error categories via duck-typing
packages/cli/src/commands/fmt.ts Converted to typed ValidationError, updated both formatFile and expandFormatPaths Result.tryPromise handlers to preserve error categories
packages/cli/src/commands/init.ts Converted to typed ValidationError using .create() and .fromMessage() methods, updated Result.tryPromise catch handler
packages/cli/src/commands/scan.ts Converted to typed ValidationError, updated Result.tryPromise catch handler to preserve error categories

Last reviewed commit: 16bb9a7

galligan commented Feb 22, 2026

Copy link
Copy Markdown
Contributor Author

Replace throw new Error(...) with typed contract errors
(ValidationError, NotFoundError) in modify and add command handlers.
Update Result.tryPromise catch handlers to preserve error category
instead of wrapping all errors as InternalError.

🤘🏻 In-collaboration-with: [Claude Code](https://claude.com/claude-code)
Convert throws in init.ts, remove.ts, scan.ts, update.ts, fmt.ts,
lint.ts, check.ts, and doctor.ts to use typed contract errors
(ValidationError, InternalError) instead of generic Error. Update all
Result.tryPromise catch handlers to preserve error categories via
AnyKitError duck-typing.

🤘🏻 In-collaboration-with: [Claude Code](https://claude.com/claude-code)
@galligan galligan force-pushed the outfitter/v2-core-results branch from 8a4de2f to 8eb153a Compare February 22, 2026 03:42
@galligan galligan force-pushed the outfitter/v2-cli-handlers branch from aa7415d to 16bb9a7 Compare February 22, 2026 03:42
@galligan galligan marked this pull request as ready for review February 22, 2026 04:07
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