Fix silent script failures from ((var++)) with set -e#332
Open
emanuel-r wants to merge 1 commit intobuildermethods:mainfrom
Open
Fix silent script failures from ((var++)) with set -e#332emanuel-r wants to merge 1 commit intobuildermethods:mainfrom
emanuel-r wants to merge 1 commit intobuildermethods:mainfrom
Conversation
|
Tested this fix locally and it solves the issue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug #1: Silent Script Failure from ((var++)) with set -e
Severity: High — scripts silently exit with no error message
Problem
Multiple scripts use the pattern ((count++)) to increment counters. When the variable is 0, the expression ((0++)) evaluates to 0, which bash treats as exit status 1 (falsy). Combined with set -e (which all three scripts use), this silently kills the script.
Affected Files and Lines
scripts/project-install.sh:
Line 244: ((profile_file_count++)) — standards installation counter
Line 248: ((profiles_used++)) — profiles used counter
Line 401: ((count++)) — commands installation counter
Line 448: ((chain_depth++)) — inheritance chain display counter
scripts/common-functions.sh:
Line 222: ((count++)) — file copy counter
scripts/sync-to-profile.sh:
Line 197: ((i++)) — profile listing counter
Line 276: ((i++)) — file display counter
Line 452: ((backup_count++)) — backup counter
Line 480: ((sync_count++)) — sync counter
Reproduction
bash# This demonstrates the issue:
bash -c 'set -e; count=0; ((count++)); echo "This never prints"'
Compare with a non-zero start value (works fine):
bash -c 'set -e; count=1; ((count++)); echo "This prints"'
Observed Behavior
Running project-install.sh on a fresh v3 install:
Script prints "Configuration:" and then silently exits
No error message displayed
Exit happens at the inheritance chain display loop (line 448)
If that line is fixed, the script proceeds but installs only 1 of 5 commands before silently exiting at line 401
Fix
Replace all ((var++)) patterns with the POSIX-safe form:
bash# Before (fails when var is 0 with set -e)
((count++))
After (always safe)
count=$((count + 1))
Note: for ((i=0; i<n; i++)) loop constructs are NOT affected — only standalone ((var++)) statements.
References
This is a well-documented bash behavior:
https://www.gnu.org/software/bash/manual/html_node/Shell-Arithmetic.html
The (( )) compound command returns exit status 1 when the expression evaluates to 0