Skip to content

fix(repo): report download failures in install.sh - #3041

Merged
kopernic-pl merged 1 commit into
stoplightio:developfrom
Sunasuna24:bugfix/install-sh-error-reporting
Aug 27, 2026
Merged

fix(repo): report download failures in install.sh#3041
kopernic-pl merged 1 commit into
stoplightio:developfrom
Sunasuna24:bugfix/install-sh-error-reporting

Conversation

@Sunasuna24

Copy link
Copy Markdown
Contributor

Fixes #3040.

Checklist

  • Tests added / updated
  • Docs added / updated

Does this PR introduce a breaking change?

  • Yes
  • No

Additional context

Three lines in the download block combined to swallow connection-level failures, so curl -L .../install.sh | sh exited non-zero with no explanation at all. Reasoning is in #3040.

-STATUS=$(curl -sL -w %{http_code} -o "$SRC" "$URL")
-if [ $STATUS -ge 200 ] & [ $STATUS -le 308 ]; then
+STATUS=$(curl -sL -w "%{http_code}" -o "$SRC" "$URL") || STATUS=000
+if [ "$STATUS" -ge 200 ] && [ "$STATUS" -le 308 ]; then
   mv "$SRC" "$DEST"
   chmod +x "$DEST"
   echo "Spectral was installed to: ${DEST}"
 else
-  rm "$SRC"
+  rm -f "$SRC"
  • || STATUS=000 stops set -eu from terminating on the assignment, so a curl failure now falls through to the error branch that already exists instead of exiting with curl's own status.
  • &&& makes the lower bound actually apply. With & the first test is backgrounded and its result discarded, leaving the condition as -le 308 alone — which would accept 000 as success once the line above stops exiting early. The two have to change together.
  • rm -f lets the error branch finish when curl never created the output file; previously rm failed there and set -e killed the script before the message on the next line.

The two quoting changes sit on lines already being touched and clear the remaining shellcheck notes.

Verification

case before after
no network exit 6, no output Error requesting. Download binary from <URL>, exit 1
version that doesn't exist (404) already correct unchanged
normal install works works
Commands and output
# no network
$ docker run --rm --network none --user root -w /tmp \
    -v "$PWD/scripts/install.sh:/install.sh:ro" \
    curlimages/curl:latest sh /install.sh 6.16.3; echo "exit: $?"
Installing on Alpine Linux.
Error requesting. Download binary from https://github.com/stoplightio/spectral/releases/download/v6.16.3/spectral-alpine-arm64
exit: 1

# version that doesn't exist
$ ... sh /install.sh 99.99.99; echo "exit: $?"
Installing on Alpine Linux.
Error requesting. Download binary from https://github.com/stoplightio/spectral/releases/download/v99.99.99/spectral-alpine-arm64
exit: 1

# normal install, unchanged
$ ... sh /install.sh 6.16.3; echo "exit: $?"
Spectral was installed to: /usr/local/bin/spectral
exit: 0
$ ls -l /usr/local/bin/spectral && /usr/local/bin/spectral --version
-rwxr-xr-x 1 root root 78334324 /usr/local/bin/spectral
6.16.3

shellcheck on this file goes from 5 findings to 0, including the one it classifies as an error:

54:24: error: Use && for logical AND. Single & will background and return true. [SC2265]

No tests are included — there's no harness for the shell installer, and reproducing the failure needs a network-isolated container. Happy to add coverage if you'd like it.

@Sunasuna24
Sunasuna24 requested a review from a team as a code owner August 9, 2026 18:34
@kopernic-pl
kopernic-pl requested a balanced review from Copilot August 26, 2026 16:16
@kopernic-pl
kopernic-pl force-pushed the bugfix/install-sh-error-reporting branch from 60cc6e5 to 7709994 Compare August 26, 2026 16:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes silent installer failures by routing curl connection errors through the existing error path.

Changes:

  • Handles failed downloads without premature set -e termination.
  • Corrects HTTP status validation and safely removes missing files.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

A connection-level failure (DNS, refused, TLS, timeout) left the script exiting with
curl's status and no message, because set -eu terminates on the assignment before the
status check runs. Bind the failure to 000 so the existing error branch is reached.

The lower bound in that check never took effect either: a single & backgrounds the first
test and discards its result, leaving the condition as -le 308 alone. It only becomes
reachable once the curl failure stops exiting early, so both change together.

rm in the error branch also failed when curl never created the output file, terminating
the script before the message it was about to print. Use rm -f.
@kopernic-pl
kopernic-pl force-pushed the bugfix/install-sh-error-reporting branch from 7709994 to 168a76e Compare August 27, 2026 09:09
@kopernic-pl
kopernic-pl enabled auto-merge (squash) August 27, 2026 09:10
@kopernic-pl
kopernic-pl merged commit 01789ae into stoplightio:develop Aug 27, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

install.sh exits without an error message when the download cannot connect

4 participants