Skip to content

Commit 8310246

Browse files
Copilotrajbos
andcommitted
Add error handling to refreshTools.sh to fix null hostname error
Co-authored-by: rajbos <6085745+rajbos@users.noreply.github.com>
1 parent dc5c934 commit 8310246

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

.devcontainer/refreshTools.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,28 @@ TOOLS_MARKER_FILE="$MARKER_DIR/tools"
1212

1313
sudo mkdir -p "$MARKER_DIR"
1414

15+
# Check if TEMPLATE_PAT is set
16+
if [ -z "$TEMPLATE_PAT" ]; then
17+
echo "TEMPLATE_PAT environment variable is not set. Skipping tools update."
18+
exit 0
19+
fi
20+
1521
# Fetch the latest release information
1622
LATEST_RELEASE=$(curl -s -H "Authorization: token $TEMPLATE_PAT" https://api.github.com/repos/github/spark-template/releases/latest)
1723

24+
# Check if the API call succeeded
25+
if [ $? -ne 0 ] || [ -z "$LATEST_RELEASE" ]; then
26+
echo "Failed to fetch release information from GitHub. Skipping tools update."
27+
exit 0
28+
fi
29+
1830
# Check if marker file exists and has the same release ID
1931
RELEASE_ID=$(echo "$LATEST_RELEASE" | jq -r '.id')
32+
if [ "$RELEASE_ID" == "null" ] || [ -z "$RELEASE_ID" ]; then
33+
echo "Invalid release data received from GitHub. Skipping tools update."
34+
exit 0
35+
fi
36+
2037
if [ -f "$RELEASE_MARKER_FILE" ] && [ "$(cat "$RELEASE_MARKER_FILE")" == "$RELEASE_ID" ]; then
2138
echo "Already at the latest release. Skipping download."
2239
exit 0
@@ -28,6 +45,13 @@ TEMP_DIR=$(mktemp -d)
2845
cd $TEMP_DIR
2946

3047
DOWNLOAD_URL=$(echo "$LATEST_RELEASE" | jq -r '.assets[0].url')
48+
if [ "$DOWNLOAD_URL" == "null" ] || [ -z "$DOWNLOAD_URL" ]; then
49+
echo "No download URL found in release data. Skipping tools update."
50+
cd - >/dev/null
51+
rm -rf $TEMP_DIR
52+
exit 0
53+
fi
54+
3155
curl -L -o dist.zip -H "Authorization: token $TEMPLATE_PAT" -H "Accept: application/octet-stream" "$DOWNLOAD_URL"
3256

3357
unzip -o dist.zip

0 commit comments

Comments
 (0)