Skip to content

Commit b23f50e

Browse files
committed
🎨 Better erroring/checking
1 parent 7e03ad9 commit b23f50e

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

hooks/post-command

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ if [[ -z "${BEP_FILE}" && -n "${BAZEL_COMMAND}" ]]; then
2222
BEP_FILE="${BASH_REMATCH[1]}"
2323
echo "Detected BEP file from Bazel command: ${BEP_FILE}"
2424
else
25-
# No BEP file specified in command, need to check if skip is enabled
25+
# No BEP file specified in command, check if skip is enabled
2626
if [[ "${SKIP_IF_NO_BEP}" == "true" ]]; then
27-
echo "No BEP file found and skip_if_no_bep is true, skipping annotation"
27+
echo "No BEP file found in command and skip_if_no_bep is true, skipping annotation"
2828
exit 0
2929
fi
30-
echo "Warning: No BEP file specified and couldn't detect one from Bazel command"
30+
echo "Error: No BEP file found in command"
3131
exit 1
3232
fi
3333
fi
@@ -40,7 +40,7 @@ if [[ -z "${BEP_FILE}" ]]; then
4040
"${BUILDKITE_BUILD_CHECKOUT_PATH:-$PWD}/bazel-bep.json"
4141
"${BUILDKITE_BUILD_CHECKOUT_PATH:-$PWD}/bep.json"
4242
)
43-
43+
4444
for location in "${COMMON_LOCATIONS[@]}"; do
4545
if [[ -f "$location" ]]; then
4646
BEP_FILE="$location"
@@ -50,16 +50,36 @@ if [[ -z "${BEP_FILE}" ]]; then
5050
done
5151
fi
5252

53-
# Exit if no BEP file found after all attempts
54-
if [[ -z "${BEP_FILE}" || ! -f "${BEP_FILE}" ]]; then
53+
# Check if we have a BEP file
54+
if [[ -z "${BEP_FILE}" ]]; then
5555
if [[ "${SKIP_IF_NO_BEP}" == "true" ]]; then
56-
echo "No valid BEP file found and skip_if_no_bep is true, skipping annotation"
56+
echo "No BEP file specified and skip_if_no_bep is true, skipping annotation"
5757
exit 0
5858
else
59-
echo "Error: No valid BEP file found"
59+
echo "Error: No BEP file specified"
60+
exit 1
61+
fi
62+
fi
63+
64+
# Check if the BEP file exists
65+
if [[ ! -f "${BEP_FILE}" ]]; then
66+
if [[ "${SKIP_IF_NO_BEP}" == "true" ]]; then
67+
echo "BEP file not found at '${BEP_FILE}' and skip_if_no_bep is true, skipping annotation"
68+
exit 0
69+
else
70+
echo "Error: BEP file not found at '${BEP_FILE}'"
6071
exit 1
6172
fi
6273
fi
6374

6475
# Process the BEP file and create the annotation
65-
process_bep "${BEP_FILE}" "${BAZEL_COMMAND}"
76+
process_bep "${BEP_FILE}" "${BAZEL_COMMAND}" || {
77+
status=$?
78+
echo "Warning: BEP processing returned non-zero status ($status)"
79+
if [[ "${SKIP_IF_NO_BEP}" == "true" ]]; then
80+
echo "skip_if_no_bep is true, ignoring error"
81+
exit 0
82+
else
83+
exit $status
84+
fi
85+
}

0 commit comments

Comments
 (0)