From 173f6d33c0c520853b44c53461614c5e4906eeac Mon Sep 17 00:00:00 2001 From: Ojus Save Date: Mon, 26 Jan 2026 14:29:03 -0800 Subject: [PATCH] fix(render): add comprehensive error handling and logging - Disable set -e during permission testing - Add explicit error checks with clear messages - Verify token is set before starting - Add directory listings if dist/index.js missing - More verbose logging throughout - Check return codes explicitly --- scripts/render-start.sh | 58 ++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/scripts/render-start.sh b/scripts/render-start.sh index b2852466d..b65674ebc 100755 --- a/scripts/render-start.sh +++ b/scripts/render-start.sh @@ -1,17 +1,19 @@ #!/bin/sh # Render startup script - creates config and starts gateway -set -e +# Don't use set -e initially - we'll enable it after setup echo "=== Render startup script ===" echo "HOME=${HOME:-not set}" echo "CLAWDBOT_STATE_DIR=${CLAWDBOT_STATE_DIR:-not set}" echo "User: $(whoami 2>/dev/null || echo unknown)" echo "UID: $(id -u 2>/dev/null || echo unknown)" +echo "PWD: $(pwd)" # Set HOME if not set (node user's home is /home/node) if [ -z "${HOME}" ]; then - export HOME="/home/node" - if [ ! -d "${HOME}" ]; then + if [ -d "/home/node" ]; then + export HOME="/home/node" + else export HOME="/tmp" fi echo "Set HOME to: ${HOME}" @@ -20,14 +22,18 @@ fi # Use CLAWDBOT_STATE_DIR if set and writable, otherwise use HOME/.clawdbot CONFIG_DIR="${HOME}/.clawdbot" if [ -n "${CLAWDBOT_STATE_DIR}" ]; then - # Test if we can write to it - if mkdir -p "${CLAWDBOT_STATE_DIR}" 2>/dev/null && touch "${CLAWDBOT_STATE_DIR}/.test" 2>/dev/null; then + # Test if we can write to it (disable exit on error for this test) + set +e + mkdir -p "${CLAWDBOT_STATE_DIR}" 2>/dev/null + touch "${CLAWDBOT_STATE_DIR}/.test" 2>/dev/null + if [ $? -eq 0 ]; then rm -f "${CLAWDBOT_STATE_DIR}/.test" 2>/dev/null CONFIG_DIR="${CLAWDBOT_STATE_DIR}" echo "Using CLAWDBOT_STATE_DIR: ${CONFIG_DIR}" else echo "Warning: ${CLAWDBOT_STATE_DIR} not writable, using ${CONFIG_DIR}" fi + set -e fi CONFIG_FILE="${CONFIG_DIR}/clawdbot.json" @@ -35,11 +41,14 @@ CONFIG_FILE="${CONFIG_DIR}/clawdbot.json" echo "Config dir: ${CONFIG_DIR}" echo "Config file: ${CONFIG_FILE}" -# Create config directory -mkdir -p "${CONFIG_DIR}" +# Create config directory (this should always work for HOME/.clawdbot) +if ! mkdir -p "${CONFIG_DIR}" 2>/dev/null; then + echo "ERROR: Failed to create config directory: ${CONFIG_DIR}" + exit 1 +fi # Write config file -cat > "${CONFIG_FILE}" << 'EOF' +if ! cat > "${CONFIG_FILE}" << 'EOF' { "gateway": { "mode": "local", @@ -50,9 +59,19 @@ cat > "${CONFIG_FILE}" << 'EOF' } } EOF +then + echo "ERROR: Failed to write config file: ${CONFIG_FILE}" + exit 1 +fi echo "=== Config written to ${CONFIG_FILE} ===" -cat "${CONFIG_FILE}" +cat "${CONFIG_FILE}" || echo "Warning: Could not read config file" + +# Verify config file exists and is readable +if [ ! -f "${CONFIG_FILE}" ]; then + echo "ERROR: Config file does not exist: ${CONFIG_FILE}" + exit 1 +fi # Set environment variables for gateway export CLAWDBOT_STATE_DIR="${CONFIG_DIR}" @@ -66,16 +85,37 @@ echo "CLAWDBOT_CONFIG_PATH=${CLAWDBOT_CONFIG_PATH}" # Verify node is available if ! command -v node >/dev/null 2>&1; then echo "ERROR: node command not found" + echo "PATH: ${PATH}" exit 1 fi +echo "Node version: $(node --version)" + # Verify dist/index.js exists if [ ! -f "dist/index.js" ]; then echo "ERROR: dist/index.js not found" + echo "Contents of /app:" + ls -la /app 2>/dev/null || echo "Cannot list /app" + echo "Contents of current directory:" + ls -la . 2>/dev/null || echo "Cannot list current directory" exit 1 fi +echo "Found dist/index.js" + +# Check if token is set +if [ -z "${CLAWDBOT_GATEWAY_TOKEN}" ]; then + echo "ERROR: CLAWDBOT_GATEWAY_TOKEN is not set" + exit 1 +fi + +echo "Token is set (length: ${#CLAWDBOT_GATEWAY_TOKEN})" + +# Enable strict error handling for the final exec +set -e + # Start gateway +echo "Executing: node dist/index.js gateway --port 8080 --bind lan --auth token --allow-unconfigured" exec node dist/index.js gateway \ --port 8080 \ --bind lan \