From a380852c846f59b016c67da94f1e88743ed4613e Mon Sep 17 00:00:00 2001 From: uroma Date: Thu, 22 Jan 2026 16:44:39 +0000 Subject: [PATCH] Fix: Prevent script exit due to set -e with read commands Root Cause: The script has `set -e` which causes immediate exit when any command fails. When npm install fails, the script exits before showing the error message. Additionally, `read < /dev/tty` can fail in WSL or certain terminal environments, causing silent script exit. Solution: Wrap all read commands and npm install with `set +e`/`set -e` to prevent premature exit: 1. npm install command (line 708-712): - Disables set -e before capturing output - Re-enables after getting exit code - Allows error handling to execute 2. All read commands with /dev/tty: - Wrapped with set +e / set -e - Added fallback defaults: || var="default" - Added 2>/dev/null to suppress read errors - Prevents exit if /dev/tty unavailable 3. Protected read locations: - Line 698: Launch wizard prompt (already installed case) - Line 722: Launch wizard prompt (success case) - Line 761: Sudo retry prompt (defaults to "Y") - Line 773: Launch wizard prompt (sudo success case) This is critical for WSL users where /dev/tty may not work properly with curl | bash execution. Example fix: ```bash # Before (exits on read failure): read -p "Prompt? " -n 1 -r var < /dev/tty # After (continues on read failure): set +e read -p "Prompt? " -n 1 -r var < /dev/tty 2>/dev/null || var="Y" set -e ``` Co-Authored-By: Claude --- install-claude-code.sh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/install-claude-code.sh b/install-claude-code.sh index ea2958e..fd2d8df 100755 --- a/install-claude-code.sh +++ b/install-claude-code.sh @@ -693,7 +693,10 @@ install_coding_helper() { if check_coding_helper_installed; then log_info "coding-helper already installed" echo "" - read -p "Launch coding-helper wizard now? [y/N] " -n 1 -r launch_helper < /dev/tty + # Temporarily disable set -e for read command + set +e + read -p "Launch coding-helper wizard now? [y/N] " -n 1 -r launch_helper < /dev/tty 2>/dev/null || launch_helper="N" + set -e echo "" if [[ $launch_helper =~ ^[Yy]$ ]]; then launch_coding_helper @@ -701,10 +704,12 @@ install_coding_helper() { return fi - # Install the helper + # Install the helper (temporarily disable set -e to capture errors) + set +e local install_output install_output=$(npm install -g @z_ai/coding-helper 2>&1) local install_exit_code=$? + set -e if [ $install_exit_code -eq 0 ]; then # Verify installation @@ -713,7 +718,9 @@ install_coding_helper() { echo "" echo -e "${CYAN}You can now run:${NC} ${YELLOW}npx @z_ai/coding-helper${NC}" echo "" - read -p "Launch coding-helper wizard now? [y/N] " -n 1 -r launch_helper < /dev/tty + set +e + read -p "Launch coding-helper wizard now? [y/N] " -n 1 -r launch_helper < /dev/tty 2>/dev/null || launch_helper="N" + set -e echo "" if [[ $launch_helper =~ ^[Yy]$ ]]; then launch_coding_helper @@ -751,7 +758,10 @@ install_coding_helper() { echo -e "${BOLD}${YELLOW}═══════════════════════════════════════════════════════════${NC}" echo -e "${BOLD} Try installing with sudo now?${NC} ${GREEN}[Y/n]${NC} ${BOLD}(recommended)${NC}" echo -e "${BOLD}${YELLOW}═══════════════════════════════════════════════════════════${NC}" - read -p " " -n 1 -r use_sudo < /dev/tty + # Temporarily disable set -e for read command + set +e + read -p " " -n 1 -r use_sudo < /dev/tty 2>/dev/null || use_sudo="Y" + set -e echo "" # Default to Yes if user just presses Enter if [[ -z "$use_sudo" ]] || [[ $use_sudo =~ ^[Yy]$ ]]; then @@ -761,7 +771,9 @@ install_coding_helper() { if npm list -g @z_ai/coding-helper &> /dev/null 2>&1; then log_success "coding-helper installed and verified with sudo!" echo "" - read -p "Launch coding-helper wizard now? [y/N] " -n 1 -r launch_helper < /dev/tty + set +e + read -p "Launch coding-helper wizard now? [y/N] " -n 1 -r launch_helper < /dev/tty 2>/dev/null || launch_helper="N" + set -e echo "" if [[ $launch_helper =~ ^[Yy]$ ]]; then launch_coding_helper