refactor(cli): wire exitWithError() across key commands#170
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
…dlers - approve, reject, comment: fully delegated to core handlers (approveHandler, rejectHandler, commentHandler), removing createContext/client wiring - reply, edit: replaced console.error + process.exit(1) with exitWithError() (handler delegation deferred due to feature gaps in core handlers) - status, doctor: also migrated to exitWithError() for consistency - Added missing handler re-exports to packages/core/src/index.ts 🤘🏻 In-collaboration-with: [Claude Code](https://claude.com/claude-code)
e19b65d to
abcf1dd
Compare
9244256 to
056e9bc
Compare
| if (ctx.outputJson) { | ||
| await outputStructured(result, "jsonl"); | ||
| } else { | ||
| console.error(`Failed to delete comment ${displayId}: ${result.error}`); | ||
| process.exit(1); | ||
| } | ||
| process.exit(1); | ||
| exitWithError( | ||
| new Error(`Failed to delete comment ${displayId}: ${result.error}`) | ||
| ); |
There was a problem hiding this comment.
process.exit(1) called before exitWithError(), making the error handler unreachable
| if (ctx.outputJson) { | |
| await outputStructured(result, "jsonl"); | |
| } else { | |
| console.error(`Failed to delete comment ${displayId}: ${result.error}`); | |
| process.exit(1); | |
| } | |
| process.exit(1); | |
| exitWithError( | |
| new Error(`Failed to delete comment ${displayId}: ${result.error}`) | |
| ); | |
| if (ctx.outputJson) { | |
| await outputStructured(result, "jsonl"); | |
| } | |
| exitWithError( | |
| new Error(`Failed to delete comment ${displayId}: ${result.error}`) | |
| ); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/cli/src/commands/edit.ts
Line: 552-558
Comment:
`process.exit(1)` called before `exitWithError()`, making the error handler unreachable
```suggestion
if (ctx.outputJson) {
await outputStructured(result, "jsonl");
}
exitWithError(
new Error(`Failed to delete comment ${displayId}: ${result.error}`)
);
```
How can I resolve this? If you propose a fix, please make it concise.| if (ctx.outputJson) { | ||
| await outputStructured(result, "jsonl"); | ||
| } else { | ||
| console.error(`Failed to delete comment ${displayId}: ${result.error}`); | ||
| process.exit(1); | ||
| } | ||
| process.exit(1); | ||
| exitWithError( | ||
| new Error(`Failed to delete comment ${displayId}: ${result.error}`) | ||
| ); |
There was a problem hiding this comment.
process.exit(1) called before exitWithError(), making the error handler unreachable
| if (ctx.outputJson) { | |
| await outputStructured(result, "jsonl"); | |
| } else { | |
| console.error(`Failed to delete comment ${displayId}: ${result.error}`); | |
| process.exit(1); | |
| } | |
| process.exit(1); | |
| exitWithError( | |
| new Error(`Failed to delete comment ${displayId}: ${result.error}`) | |
| ); | |
| if (ctx.outputJson) { | |
| await outputStructured(result, "jsonl"); | |
| } | |
| exitWithError( | |
| new Error(`Failed to delete comment ${displayId}: ${result.error}`) | |
| ); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/cli/src/commands/edit.ts
Line: 591-597
Comment:
`process.exit(1)` called before `exitWithError()`, making the error handler unreachable
```suggestion
if (ctx.outputJson) {
await outputStructured(result, "jsonl");
}
exitWithError(
new Error(`Failed to delete comment ${displayId}: ${result.error}`)
);
```
How can I resolve this? If you propose a fix, please make it concise.| if (ctx.outputJson) { | ||
| await outputStructured(result, "jsonl"); | ||
| } else { | ||
| console.error(`Failed to update comment ${displayId}: ${result.error}`); | ||
| process.exit(1); | ||
| } | ||
| process.exit(1); | ||
| exitWithError( | ||
| new Error(`Failed to update comment ${displayId}: ${result.error}`) | ||
| ); |
There was a problem hiding this comment.
process.exit(1) called before exitWithError(), making the error handler unreachable
| if (ctx.outputJson) { | |
| await outputStructured(result, "jsonl"); | |
| } else { | |
| console.error(`Failed to update comment ${displayId}: ${result.error}`); | |
| process.exit(1); | |
| } | |
| process.exit(1); | |
| exitWithError( | |
| new Error(`Failed to update comment ${displayId}: ${result.error}`) | |
| ); | |
| if (ctx.outputJson) { | |
| await outputStructured(result, "jsonl"); | |
| } | |
| exitWithError( | |
| new Error(`Failed to update comment ${displayId}: ${result.error}`) | |
| ); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/cli/src/commands/edit.ts
Line: 617-623
Comment:
`process.exit(1)` called before `exitWithError()`, making the error handler unreachable
```suggestion
if (ctx.outputJson) {
await outputStructured(result, "jsonl");
}
exitWithError(
new Error(`Failed to update comment ${displayId}: ${result.error}`)
);
```
How can I resolve this? If you propose a fix, please make it concise.| if (ctx.outputJson) { | ||
| await outputStructured(result, "jsonl"); | ||
| } else { | ||
| console.error(`Failed to update comment ${displayId}: ${result.error}`); | ||
| process.exit(1); | ||
| } | ||
| process.exit(1); | ||
| exitWithError( | ||
| new Error(`Failed to update comment ${displayId}: ${result.error}`) | ||
| ); |
There was a problem hiding this comment.
process.exit(1) called before exitWithError(), making the error handler unreachable
| if (ctx.outputJson) { | |
| await outputStructured(result, "jsonl"); | |
| } else { | |
| console.error(`Failed to update comment ${displayId}: ${result.error}`); | |
| process.exit(1); | |
| } | |
| process.exit(1); | |
| exitWithError( | |
| new Error(`Failed to update comment ${displayId}: ${result.error}`) | |
| ); | |
| if (ctx.outputJson) { | |
| await outputStructured(result, "jsonl"); | |
| } | |
| exitWithError( | |
| new Error(`Failed to update comment ${displayId}: ${result.error}`) | |
| ); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/cli/src/commands/edit.ts
Line: 656-662
Comment:
`process.exit(1)` called before `exitWithError()`, making the error handler unreachable
```suggestion
if (ctx.outputJson) {
await outputStructured(result, "jsonl");
}
exitWithError(
new Error(`Failed to update comment ${displayId}: ${result.error}`)
);
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 056e9bcc2e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const result = await commentHandler( | ||
| { pr, body, repo }, | ||
| { config, db, logger: silentLogger } | ||
| ); |
There was a problem hiding this comment.
Preserve transport errors when delegating comment creation
Routing comment through commentHandler changes failure semantics: commentHandler converts any fetchPullRequestId failure into NotFoundError (in packages/core/src/handlers/comment.ts), so auth failures or transient GitHub/network errors are now reported as “PR not found.” This breaks the new category-based exit behavior for real-world cases like expired tokens or API outages and makes retries/diagnosis incorrect.
Useful? React with 👍 / 👎.
| try { | ||
| const ctx = await createContext(options); | ||
| const config = await loadConfig(); | ||
| const db = getDatabase(); |
There was a problem hiding this comment.
Remove mandatory SQLite initialization from write-only commands
Initializing db here introduces a new hard dependency on local cache storage for a command that only performs a GitHub mutation. getDatabase() creates directories/files under the cache path (mkdirSync + openDatabase in packages/core/src/cache.ts), so fw comment can now fail before hitting GitHub in read-only/containerized environments where it previously worked.
Useful? React with 👍 / 👎.

Summary
approveHandler,rejectHandler,commentHandlerto core handlers withexitWithError()reply,edit,status,doctorcommands to useexitWithError()for error pathspackages/core/src/index.tsprocess.exit(1)(FIRE-10)Test plan
bun run checkpassesbun testpasses (298 tests)🤘🏻 In-collaboration-with: Claude Code
Greptile Summary
This PR refactors CLI commands to use
exitWithError()from@outfitter/cliinstead of rawconsole.error()+process.exit(1)patterns, implementing category-mapped exit codes (FIRE-10).Key changes:
approve,reject, andcommentcommands to use core handlers (approveHandler,rejectHandler,commentHandler) with proper error handlingreply,edit,status, anddoctorcommands to replace hardcodedprocess.exit(1)withexitWithError()packages/core/src/index.tsfor the newly exposed handlers and their typesIssues found:
apps/cli/src/commands/edit.tshas 4 instances whereprocess.exit(1)is called beforeexitWithError(), making the error handler unreachable. This defeats the purpose of the refactor since exit codes won't be properly categorized in those error paths.Confidence Score: 3/5
edit.tscontains critical logic errors whereprocess.exit(1)is called immediately beforeexitWithError(), making the new error handler unreachable in 4 error paths. This means those error cases won't benefit from category-mapped exit codes, partially defeating the PR's purpose.Important Files Changed
approveHandlerfrom core withexitWithError()replacingprocess.exit(1)commentHandlerfrom core withexitWithError()replacingprocess.exit(1)rejectHandlerfrom core withexitWithError()replacingprocess.exit(1)exitWithError(), but has inconsistent error handling withprocess.exit(1)still present before someexitWithError()callsLast reviewed commit: 056e9bc