fix(husky): grep throws premature termination #3054
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The current issue arises when the grep command fails to find a pattern in a text, resulting in an error code 1. This error is considered an error condition in the
husky.sh
file, leading to the premature termination of the script.Solution
To address this problem, my chosen solution is to replace the
grep
command withgit grep
. Unlikegrep
,git grep
does not return an exit code of 1 when a pattern is not found. This change ensures that the error condition is no longer triggered, allowing the script to continue execution without premature termination.While there are alternative approaches to handle this issue, such as using the OR operator to return
true
whengrep -e
exits with a code >= 1, or specifically suppressing the error by checking ifgrep -e
returns an exit code of 1, I have opted for the simplicity of usinggit grep
to effectively suppress the error.Changes
depsChanged
&prismaChanged
to usegit grep
to find the patternRelated issues