From f4f8c323292f24b9b7cbe08ca60799904fd21c32 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Sat, 29 Aug 2026 15:09:21 +0200 Subject: [PATCH] fix: make prime_profile.sh fail loudly instead of exiting 0 or dying silently Co-Authored-By: Claude Opus 5 (1M context) --- scripts/prime_profile.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/prime_profile.sh b/scripts/prime_profile.sh index 318185b..73b9b6d 100755 --- a/scripts/prime_profile.sh +++ b/scripts/prime_profile.sh @@ -35,11 +35,12 @@ RECIPIENTS=() # shellcheck source-path=SCRIPTDIR source=scripts/lib_signal.sh . "${SCRIPT_DIR}/lib_signal.sh" +# Prints only. The caller decides the exit code, so a usage *error* cannot +# exit 0 and be read as success by whatever ran this. usage() { echo "Usage: ${SCRIPT_NAME} + [+ ...]" echo "Sends one DM from the bot so the recipient's client learns its" echo "profile key, which makes a later group add land as a real join." - exit 0 } validate_requirements() { @@ -47,7 +48,8 @@ validate_requirements() { command -v jq >/dev/null || { echo "Error: jq is required" >&2; exit 1; } if [[ ${#RECIPIENTS[@]} -eq 0 ]]; then echo "Error: at least one recipient number is required" >&2 - usage + usage >&2 + exit 1 fi local number for number in "${RECIPIENTS[@]}"; do @@ -66,7 +68,11 @@ validate_requirements() { # typed twice is a number that can be typed differently the second time. bot_number() { local number - number="$(grep -E '^PHONE_NUMBER=' "${REPO_ROOT}/.env" | head -1 | cut -d= -f2-)" + # `|| true`: under `set -e` a grep that matches nothing kills the whole + # subshell, so the error message below would never print and the script + # would exit 1 silently -- the failure mode this repo exists to gate. + number="$(grep -E '^PHONE_NUMBER=' "${REPO_ROOT}/.env" || true)" + number="$(printf '%s' "$number" | head -1 | cut -d= -f2-)" if [[ -z "$number" ]]; then echo "Error: PHONE_NUMBER is not set in ${REPO_ROOT}/.env" >&2 return 1 @@ -113,6 +119,7 @@ while [[ $# -gt 0 ]]; do case $1 in -h | --help) usage + exit 0 ;; -*) echo "Unknown option: $1" >&2