Skip to content

fix(tokens): set +e in test.sh silently swallows curl failures in demo script #6

@Prachi194agrawal

Description

@Prachi194agrawal

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions