fix: emit actionable error when --edit cannot find COMMIT_EDITMSG (#589)#4755
Conversation
Catch ENOENT from reading the edit file and throw a message that explains --edit is meant for a commit-msg hook and points at --from / --to or --edit <file> for other use cases. Avoids the raw fs error on fresh checkouts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Review Summary by QodoEmit actionable error when --edit cannot find COMMIT_EDITMSG
WalkthroughsDescription• Catch ENOENT error when reading COMMIT_EDITMSG file • Provide actionable error message explaining --edit usage • Guide users to --from/--to or --edit <file> alternatives • Add test case for missing COMMIT_EDITMSG scenario Diagramflowchart LR
A["getEditCommit function"] -->|readFile fails| B["Catch ENOENT error"]
B -->|Check error code| C["Throw helpful error message"]
C -->|Explain --edit usage| D["Guide to alternatives"]
D -->|--from/--to or --edit file| E["User gets clear guidance"]
File Changes1. @commitlint/read/src/get-edit-commit.ts
|
Code Review by Qodo
1. --edit ENOENT now throws
|
There was a problem hiding this comment.
Pull request overview
This PR improves the UX of @commitlint/read when edit: true (CLI: --edit) is used in a repository where .git/COMMIT_EDITMSG does not exist (e.g., a fresh checkout with no commits yet), replacing the raw filesystem error with a more actionable message and adding a regression test.
Changes:
- Catch
ENOENTwhen reading the edit commit message file and throw an explanatory error message. - Add a test asserting the actionable error is thrown on a freshly initialized repo without
COMMIT_EDITMSG.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| @commitlint/read/src/get-edit-commit.ts | Wraps fs.readFile to translate ENOENT into a more actionable error message. |
| @commitlint/read/src/read.test.ts | Adds a regression test for edit: true behavior on a fresh repo without COMMIT_EDITMSG. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Attach the caught ENOENT as `cause` to satisfy preserve-caught-error and aid debugging. - When `--edit <file>` was supplied, point users at the path they passed instead of the commit-msg-hook guidance. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Mmm, looks like code_quality CI is not being run in PRs? |
|
Actually, it ran, I'm confused. |
The --edit error handling change in #4755 merged with an unformatted multi-line throw expression, breaking the format check on subsequent CI runs. Collapse it to oxfmt's expected single-line form. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Fixes: #589
Catch ENOENT from reading the edit file and throw a message that explains --edit is meant for a commit-msg hook and points at --from / --to or --edit for other use cases. Avoids the raw fs error on fresh checkouts.