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 <noreply@anthropic.com>
This commit is contained in:
@@ -693,7 +693,10 @@ install_coding_helper() {
|
|||||||
if check_coding_helper_installed; then
|
if check_coding_helper_installed; then
|
||||||
log_info "coding-helper already installed"
|
log_info "coding-helper already installed"
|
||||||
echo ""
|
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 ""
|
echo ""
|
||||||
if [[ $launch_helper =~ ^[Yy]$ ]]; then
|
if [[ $launch_helper =~ ^[Yy]$ ]]; then
|
||||||
launch_coding_helper
|
launch_coding_helper
|
||||||
@@ -701,10 +704,12 @@ install_coding_helper() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install the helper
|
# Install the helper (temporarily disable set -e to capture errors)
|
||||||
|
set +e
|
||||||
local install_output
|
local install_output
|
||||||
install_output=$(npm install -g @z_ai/coding-helper 2>&1)
|
install_output=$(npm install -g @z_ai/coding-helper 2>&1)
|
||||||
local install_exit_code=$?
|
local install_exit_code=$?
|
||||||
|
set -e
|
||||||
|
|
||||||
if [ $install_exit_code -eq 0 ]; then
|
if [ $install_exit_code -eq 0 ]; then
|
||||||
# Verify installation
|
# Verify installation
|
||||||
@@ -713,7 +718,9 @@ install_coding_helper() {
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e "${CYAN}You can now run:${NC} ${YELLOW}npx @z_ai/coding-helper${NC}"
|
echo -e "${CYAN}You can now run:${NC} ${YELLOW}npx @z_ai/coding-helper${NC}"
|
||||||
echo ""
|
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 ""
|
echo ""
|
||||||
if [[ $launch_helper =~ ^[Yy]$ ]]; then
|
if [[ $launch_helper =~ ^[Yy]$ ]]; then
|
||||||
launch_coding_helper
|
launch_coding_helper
|
||||||
@@ -751,7 +758,10 @@ install_coding_helper() {
|
|||||||
echo -e "${BOLD}${YELLOW}═══════════════════════════════════════════════════════════${NC}"
|
echo -e "${BOLD}${YELLOW}═══════════════════════════════════════════════════════════${NC}"
|
||||||
echo -e "${BOLD} Try installing with sudo now?${NC} ${GREEN}[Y/n]${NC} ${BOLD}(recommended)${NC}"
|
echo -e "${BOLD} Try installing with sudo now?${NC} ${GREEN}[Y/n]${NC} ${BOLD}(recommended)${NC}"
|
||||||
echo -e "${BOLD}${YELLOW}═══════════════════════════════════════════════════════════${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 ""
|
echo ""
|
||||||
# Default to Yes if user just presses Enter
|
# Default to Yes if user just presses Enter
|
||||||
if [[ -z "$use_sudo" ]] || [[ $use_sudo =~ ^[Yy]$ ]]; then
|
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
|
if npm list -g @z_ai/coding-helper &> /dev/null 2>&1; then
|
||||||
log_success "coding-helper installed and verified with sudo!"
|
log_success "coding-helper installed and verified with sudo!"
|
||||||
echo ""
|
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 ""
|
echo ""
|
||||||
if [[ $launch_helper =~ ^[Yy]$ ]]; then
|
if [[ $launch_helper =~ ^[Yy]$ ]]; then
|
||||||
launch_coding_helper
|
launch_coding_helper
|
||||||
|
|||||||
Reference in New Issue
Block a user