opencommit
opencommit copied to clipboard
feat(prepare-commit-msg): Continue creating a commit even when an AI provider error occurs
trafficstars
Why is this PR needed?
I encountered an issue when using the prepare-commit-msg hook to automatically generate commit messages. When an API call to the AI provider fails, the prepare-commit-msg hook also fails, and a commit cannot be created unless the hook is disabled. Such API failures can occur due to network issues or other temporary problems.
It is annoying to have to run oco hook unset; git commit; oco hook set every time to work around this issue.
What has changed
- The hook now continues to create a commit even when an error occurs by catching the error. To make it noticeable when such an issue occurs, the error message is written to the temporary commit message file.
- The
commitMessagePromisesloop previously prevented errors from being caught; is has been replaced withPromise.allinstead.
- The
How does this work
When a commit is created during a network issue, the following message is displayed in your $EDITOR :
# ---------- [OpenCommit] ---------- #
# Failed to generate the commit message.
# To cancel the commit, just close this window without making any changes.
# Error: Connection error.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch error-on-hook