Skip to content

Fix: gh_run exits prematurely under set -e #125

Description

@codeforester

Summary

gh_run in lib/bash/gh/lib_gh.sh is broken in scripts that use set -e (or set -euo pipefail).

Root cause

gh_run() {
    local status

    gh_require_cli || return 1
    gh "$@"          # ← unchecked: with set -e, a failing gh exits the script here
    status=$?        # ← never reached on failure
    ((status == 0)) && return 0
    gh_report_command_failure "$status" "$@"
}

gh "$@" is a plain command in the function body. With set -e active, any non-zero exit from gh causes the calling script to exit immediately — before status=$? is captured. gh_report_command_failure never runs, so the caller gets a silent abrupt exit instead of a controlled error with diagnostics.

The BATS suite doesn't expose this because capture_command does set +e before calling.

Fix

gh_run() {
    local status=0

    gh_require_cli || return 1
    gh "$@" || status=$?
    ((status == 0)) && return 0
    gh_report_command_failure "$status" "$@"
}

The || status=$? pattern keeps gh on the left side of ||, which is exempt from set -e.

Test gap

Add a test that calls gh_run from a script with set -euo pipefail active and a fake gh that returns non-zero, verifying that gh_report_command_failure output appears rather than a silent exit.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions