BoundaryML/baml · error
`gh {}` failed: {}
Error message
`gh {}` failed: {} What it means
Wraps any non-zero exit of the GitHub CLI. The `gh` command (e.g. `gh run list`, `gh run download`, `gh api`) ran but returned failure, and its stderr is surfaced verbatim. This is how the size-gate reports authentication, rate-limit, and not-found problems from gh itself.
Source
Thrown at baml_language/crates/tools_size_gate/src/fetch.rs:205
&& path
.extension()
.is_some_and(|e| e.eq_ignore_ascii_case("json"))
{
out.push(path);
}
}
Ok(())
}
/// Run `gh` with `args`, returning stdout. Surfaces a clear error if `gh`
/// is missing or unauthenticated.
fn gh(args: &[&str]) -> Result<String> {
let output = Command::new("gh").args(args).output().context(
"failed to run `gh` — install the GitHub CLI and run `gh auth login` \
(or pass explicit report files instead of --branch)",
)?;
if !output.status.success() {
bail!(
"`gh {}` failed: {}",
args.join(" "),
String::from_utf8_lossy(&output.stderr).trim()
);
}
Ok(String::from_utf8_lossy(&output.stdout).into_owned())
}
View on GitHub (pinned to bd85ce9dee)
Solutions
- Read the stderr in this message — it contains gh's own diagnostic
- Run `gh auth login` locally or set GH_TOKEN in CI
- Verify the branch/run exists: gh run list --branch <branch>
- Run the same gh command manually to reproduce and debug
Example fix
// before
gh run download 123 --repo org/repo
// after, with auth fixed in CI
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# or locally: gh auth login Defensive patterns
Strategy: try-catch
Validate before calling
if std::process::Command::new("gh").arg("auth").arg("status").status().map(|s| !s.success()).unwrap_or(true) {
eprintln!("gh not authenticated; run `gh auth login` or set GH_TOKEN");
std::process::exit(1);
} Try / catch
match result {
Err(e) if e.to_string().contains("`gh") => {
eprintln!("gh invocation failed: {e}. Check `gh auth status` and that the run/branch exists.");
// fall back to explicit report files
}
Err(e) => return Err(e),
Ok(v) => v,
} Prevention
- Always set GH_TOKEN/GITHUB_TOKEN in CI before invoking size-gate --branch
- Run `gh auth status` as a CI preflight step
- Validate the branch/run exists with `gh run list` before downloading
- Keep the gh CLI updated in CI images
When it happens
Trigger: Called by fetch_branch_reports and run_has_all_reports whenever a gh subprocess exits non-zero: bad auth token, network failure, nonexistent run/branch, or invalid gh arguments.
Common situations: gh not authenticated in CI (no GH_TOKEN); querying a branch/run that does not exist; rate limiting; gh CLI version too old for the flags used; corporate proxy blocking api.github.com.
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
- `baml pack` failed for fixture {}
- no completed `{CI_WORKFLOW}` runs found on branch `{branch}`
- expected {} size-gate reports from run {run_id}, found {}
- cargo metadata failed
- reports contained no artifacts to bake
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/1fe04adb26547611.
Report an issue: GitHub.