From ac3188192716c713404d5ecdb243515879a5fb5a Mon Sep 17 00:00:00 2001 From: Tim Haines Date: Fri, 24 Jul 2026 12:24:33 -0500 Subject: [PATCH 1/4] Improve error handling in post-cdash-status --- post-cdash-status | 52 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/post-cdash-status b/post-cdash-status index 85ae473..c472aea 100755 --- a/post-cdash-status +++ b/post-cdash-status @@ -1,7 +1,5 @@ #!/bin/bash -set -eo pipefail - readonly API_BASE="https://api.github.com/repos/${GITHUB_REPOSITORY}" function require_cmd() { @@ -28,12 +26,27 @@ require_env_var "GITHUB_TOKEN" #============================================================================== -statuses=$(curl -q -s \ - -H "Content-Type: application/json" \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "${API_BASE}/commits/${COMMIT_SHA}/statuses" |\ - jq -r '[.[].context] | @json') +readonly status_response=$( + curl -q -s \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "${API_BASE}/commits/${COMMIT_SHA}/statuses") + +# The API returns an empty array if no statuses were found +# This can happen if the COMMIT_SHA doesn't point to the head of the branch/PR +if [ "true" == $(jq -r '. == []' <<<$status_response) ]; then + echo "No statuses found for '${API_BASE}/commits/${COMMIT_SHA}'" + exit 1 +fi + +readonly statuses=$(jq -r '[.[].context] | @json' <<< $status_response) +if [ -z "$statuses" ]; then + echo "Failed to parse statuses for '${API_BASE}/commits/${COMMIT_SHA}'" + echo -e "Request returned:\n$status_response" + exit 1 +fi post_body="$(cat< Date: Thu, 30 Jul 2026 09:44:02 -0500 Subject: [PATCH 2/4] Add back global error handling --- post-cdash-status | 2 ++ 1 file changed, 2 insertions(+) diff --git a/post-cdash-status b/post-cdash-status index c472aea..7286730 100755 --- a/post-cdash-status +++ b/post-cdash-status @@ -1,5 +1,7 @@ #!/bin/bash +set -eo pipefail + readonly API_BASE="https://api.github.com/repos/${GITHUB_REPOSITORY}" function require_cmd() { From 5dc40b4d9cea3157077d7b248b4e986bb30bee63 Mon Sep 17 00:00:00 2001 From: Tim Haines Date: Thu, 30 Jul 2026 09:44:21 -0500 Subject: [PATCH 3/4] Use unique exit codes --- post-cdash-status | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/post-cdash-status b/post-cdash-status index 7286730..169b967 100755 --- a/post-cdash-status +++ b/post-cdash-status @@ -47,7 +47,7 @@ readonly statuses=$(jq -r '[.[].context] | @json' <<< $status_response) if [ -z "$statuses" ]; then echo "Failed to parse statuses for '${API_BASE}/commits/${COMMIT_SHA}'" echo -e "Request returned:\n$status_response" - exit 1 + exit 2 fi post_body="$(cat< Date: Thu, 30 Jul 2026 09:47:13 -0500 Subject: [PATCH 4/4] Update message for bad POST --- post-cdash-status | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post-cdash-status b/post-cdash-status index 169b967..d934700 100755 --- a/post-cdash-status +++ b/post-cdash-status @@ -75,7 +75,7 @@ if [ "true" == $(jq -re "all(. != \"${GITHUB_STATUS_NAME}\")" <<<"${statuses}") if [ "false" == $(jq -r 'has("creator")') <<<"$response" ]; then echo "Failed to create status for '${API_BASE}/commits/${COMMIT_SHA}'" - echo "$response" + echo -e "Request returned:\n$response" exit 3 fi else