Bug Description
samples/tokens/scripts/test.sh uses set +e at the script entry point, which
instructs bash to ignore all non-zero exit codes. Combined with trap exit 1 INT
(which only catches Ctrl+C), this means every curl -f call inside run_test() can
fail silently — the script continues executing subsequent steps and exits with code 0,
falsely reporting the demo as successful.
Affected File
samples/tokens/scripts/test.sh
Root Cause
Line 64 (original):
set +e # ← errors ignored
set -o pipefail
trap exit 1 INT # ← only handles Ctrl+C, not curl failures
When curl -f returns a non-zero exit code (e.g. HTTP 4xx/5xx or connection refused),
bash ignores it under set +e and moves to the next command.
Proof (terminal reproduction)
# With set +e (original behaviour): failure is swallowed
set +e
curl -f -sS http://127.0.0.1:1 >/dev/null
echo "curl_exit=$?" # curl_exit=7
echo "continued_after_failure=yes" # continued_after_failure=yes ← BUG
# With set -e (fixed behaviour): script stops on failure
bash -c 'set -e; curl -f -sS http://127.0.0.1:1 >/dev/null; echo "continued=yes"'
# subshell_exit=7 ← execution halted correctly, "continued=yes" never printed
Impact
- The token issue step (
POST /issuer/issue) can fail and the script still proceeds
to transfer and balance-check calls, which then operate on a non-existent token.
- Demo output appears to succeed (
exit 0) even when the network is broken.
- CI/CD pipelines using
make test would never catch integration failures.
Fix
Replace set +e with set -e, upgrade the trap to handle ERR (any error) in
addition to INT (Ctrl+C), and guard the cleanup() function against recursive
trap firing:
# Script Start
set -e
set -o pipefail
trap cleanup INT ERR
...
function cleanup() {
trap - INT ERR # prevent recursive trap
set +e
stop_network
exit 1
}
Diff Summary
|
Before |
After |
| Error mode |
set +e (ignore errors) |
set -e (exit on error) |
| Trap signals |
trap exit 1 INT |
trap cleanup INT ERR |
| cleanup() guard |
missing |
trap - INT ERR added |
Bug Description
samples/tokens/scripts/test.shusesset +eat the script entry point, whichinstructs bash to ignore all non-zero exit codes. Combined with
trap exit 1 INT(which only catches Ctrl+C), this means every
curl -fcall insiderun_test()canfail silently — the script continues executing subsequent steps and exits with code
0,falsely reporting the demo as successful.
Affected File
samples/tokens/scripts/test.shRoot Cause
Line 64 (original):
When
curl -freturns a non-zero exit code (e.g. HTTP 4xx/5xx or connection refused),bash ignores it under
set +eand moves to the next command.Proof (terminal reproduction)
Impact
POST /issuer/issue) can fail and the script still proceedsto transfer and balance-check calls, which then operate on a non-existent token.
exit 0) even when the network is broken.make testwould never catch integration failures.Fix
Replace
set +ewithset -e, upgrade the trap to handleERR(any error) inaddition to
INT(Ctrl+C), and guard thecleanup()function against recursivetrap firing:
Diff Summary
set +e(ignore errors)set -e(exit on error)trap exit 1 INTtrap cleanup INT ERRtrap - INT ERRadded