diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ec6de5..ee55a30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and versions are tracked in the repo-root `VERSION` file. ## [Unreleased] +### Fixed + +- Made `gh_run` report failed GitHub CLI commands even when callers enable + `set -e`, and preserved argument boundaries in GitHub command failure logs. + ## [1.2.0] - 2026-07-04 ### Added diff --git a/lib/bash/gh/lib_gh.sh b/lib/bash/gh/lib_gh.sh index 7ae895d..9d8c5e2 100644 --- a/lib/bash/gh/lib_gh.sh +++ b/lib/bash/gh/lib_gh.sh @@ -38,18 +38,24 @@ gh_auth_status_diagnostics() { gh_report_command_failure() { local status="$1" shift + local printable_args="" - log_error "GitHub command failed: gh $*" + if (($#)); then + printf -v printable_args '%q ' "$@" + printable_args="${printable_args% }" + log_error "GitHub command failed: gh $printable_args" + else + log_error "GitHub command failed: gh" + fi gh_auth_status_diagnostics || true return "$status" } gh_run() { - local status + local status=0 gh_require_cli || return 1 - gh "$@" - status=$? + gh "$@" || status=$? ((status == 0)) && return 0 gh_report_command_failure "$status" "$@" } diff --git a/lib/bash/gh/tests/lib_gh.bats b/lib/bash/gh/tests/lib_gh.bats index 68b7db1..3b05bc2 100644 --- a/lib/bash/gh/tests/lib_gh.bats +++ b/lib/bash/gh/tests/lib_gh.bats @@ -120,6 +120,70 @@ EOF [[ "$output" == *"Run 'gh auth login -h github.com' and retry."* ]] } +@test "gh_run reports command failure under set -e" { + local script="$TEST_TMPDIR/gh-run-set-e.sh" + + create_fake_gh <<'EOF' +#!/usr/bin/env bash +if [[ "$1" == "auth" && "$2" == "status" ]]; then + printf 'not logged in\n' >&2 + exit 1 +fi +printf 'command failed\n' >&2 +exit 7 +EOF + cat > "$script" <