fix: replace process.exit() with custom Error throws (#18) - #20
Conversation
|
@SAMI-CODEAI is attempting to deploy a commit to the nirvik34's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning
|
| Layer / File(s) | Summary |
|---|---|
Add custom error classes src/utils/errors.ts |
Introduce GitBunError, ValidationError, and CancellationError with names and a default cancellation message. |
Exception-based error control flow in run() src/index.ts |
run() imports the new errors and throws ValidationError for repository/staging checks and CancellationError when confirmation is rejected, replacing direct process.exit() usage. |
CLI entry point error trapping and exit bin/smartcommit.ts |
program.action wraps run() in try/catch, uses chalk for styled error output, logs cancellation messages to stdout and other errors to stderr, and exits with codes 0 or 1 appropriately. |
Tests: Errors suite src/index.test.ts |
Adds Errors tests asserting ValidationError and CancellationError name/message values (including default cancellation message). |
🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested labels: level: advanced, quality:clean, type:testing
🐰
I hopped through code with nimble paws,
Replaced abrupt exits with tidy laws.
Errors now bounce back to CLI’s gate,
Clean and testable — isn't that great?
🌿
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly and concisely describes the main change: replacing process.exit() calls with custom error throws, which aligns perfectly with the primary objective of the changeset. |
| Linked Issues check | ✅ Passed | All coding requirements from issue #18 are met: src/index.ts now throws custom Error instances instead of calling process.exit(), and bin/smartcommit.ts wraps execution in try/catch to handle errors at the CLI entry point with proper exit codes. |
| Out of Scope Changes check | ✅ Passed | All changes are directly related to the PR objective: custom error classes (src/utils/errors.ts), error handling refactoring (src/index.ts), CLI-level error catching (bin/smartcommit.ts), and test coverage (src/index.test.ts) for the new error handling approach. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/index.ts`:
- Line 28: Remove ANSI formatting from thrown errors in src/index.ts (e.g., the
throw new Error(chalk.red("Not inside a Git repository.")) and similar
occurrences), and instead throw plain-text Error instances or a lightweight
custom class like UserFacingError(message, level) that carries a severity
property; then apply chalk coloring only in the top-level presentation layer
(bin/smartcommit.ts) when catching errors by inspecting the error type or
severity. Ensure all throw sites in src/index.ts use plain messages (or the
custom class) and update bin/smartcommit.ts's catch block to colorize based on
the error instance or its level.
- Line 98: The current throw new Error("Commit cancelled.") makes cancellation
indistinguishable from failures; change to a distinct control flow: create and
throw a custom CancellationError class (e.g., class CancellationError extends
Error) or have the run() function return a result object { cancelled: true }
instead of throwing; then update bin/smartcommit.ts to catch CancellationError
(or inspect the returned result) and exit with process.exit(0) for cancellations
while still treating other errors as process.exit(1). Locate the throw site (the
string "Commit cancelled.") and the run() function as the places to implement
the custom error/return and update the CLI entrypoint to handle it.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7bab9769-36b3-4603-92a6-ea93ed56cd17
📒 Files selected for processing (2)
bin/smartcommit.tssrc/index.ts
|
@SAMI-CODEAI please resolve the coderabbit reviews |
|
🎉 This PR is included in version 1.9.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #18
Changes Made:
process.exit()calls in src/index.ts with explicit thrownErrors.try/catchblock.process.exit(1)is exclusively called at the CLI entry point.vitest) stability; no longer abruptly terminates on failure states.Summary by CodeRabbit
Bug Fixes
Tests