fix(install): restore proper error codes in install script

Revert return 0 -> return 1 for error cases to preserve fallback logic.
Functions should return 1 on failure so main() tries alternative methods.

- Error cases (missing tools, download failures, build failures): return 1
- Success cases: return 0
- Directory restoration fixes from PR #143 are preserved

Amp-Thread-ID: https://ampcode.com/threads/T-908f1690-937c-499f-bf51-ee35a9241eb2
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-24 14:58:36 -07:00
parent eaa0b71e76
commit 7931fd4f0d

View File

@@ -86,12 +86,12 @@ install_from_release() {
version=$(wget -qO- "$latest_url" | grep '"tag_name"' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/') version=$(wget -qO- "$latest_url" | grep '"tag_name"' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
else else
log_error "Neither curl nor wget found. Please install one of them." log_error "Neither curl nor wget found. Please install one of them."
return 0 return 1
fi fi
if [ -z "$version" ]; then if [ -z "$version" ]; then
log_error "Failed to fetch latest version" log_error "Failed to fetch latest version"
return 0 return 1
fi fi
log_info "Latest version: $version" log_info "Latest version: $version"
@@ -108,14 +108,14 @@ install_from_release() {
log_error "Download failed" log_error "Download failed"
cd - > /dev/null || cd "$HOME" cd - > /dev/null || cd "$HOME"
rm -rf "$tmp_dir" rm -rf "$tmp_dir"
return 0 return 1
fi fi
elif command -v wget &> /dev/null; then elif command -v wget &> /dev/null; then
if ! wget -q -O "$archive_name" "$download_url"; then if ! wget -q -O "$archive_name" "$download_url"; then
log_error "Download failed" log_error "Download failed"
cd - > /dev/null || cd "$HOME" cd - > /dev/null || cd "$HOME"
rm -rf "$tmp_dir" rm -rf "$tmp_dir"
return 0 return 1
fi fi
fi fi
@@ -125,7 +125,7 @@ install_from_release() {
if ! tar -xzf "$archive_name"; then if ! tar -xzf "$archive_name"; then
log_error "Failed to extract archive" log_error "Failed to extract archive"
rm -rf "$tmp_dir" rm -rf "$tmp_dir"
return 0 return 1
fi fi
# Determine install location # Determine install location
@@ -180,12 +180,12 @@ check_go() {
echo " - Download from https://go.dev/dl/" echo " - Download from https://go.dev/dl/"
echo " - Or use your package manager to update" echo " - Or use your package manager to update"
echo "" echo ""
return 0 return 1
fi fi
return 0 return 0
else else
return 0 return 1
fi fi
} }
@@ -209,7 +209,7 @@ install_with_go() {
return 0 return 0
else else
log_error "go install failed" log_error "go install failed"
return 0 return 1
fi fi
} }
@@ -265,12 +265,12 @@ build_from_source() {
cd - > /dev/null || cd "$HOME" cd - > /dev/null || cd "$HOME"
cd - > /dev/null cd - > /dev/null
rm -rf "$tmp_dir" rm -rf "$tmp_dir"
return 0 return 1
fi fi
else else
log_error "Failed to clone repository" log_error "Failed to clone repository"
rm -rf "$tmp_dir" rm -rf "$tmp_dir"
return 0 return 1
fi fi
} }
@@ -289,7 +289,7 @@ verify_installation() {
return 0 return 0
else else
log_error "bd was installed but is not in PATH" log_error "bd was installed but is not in PATH"
return 0 return 1
fi fi
} }