fix(shell): address shellcheck warnings, standardize error handling, add retry logic
- Fix shellcheck SC2155 (separate variable assignment from declaration) - Replace ! bool && bool pattern with [ "$bool" = true ] && [ "$bool2" = true ] - Add retry logic for git clone with configurable attempts - Add retry logic for opencode session fork - Add NETWORK_RETRY_ATTEMPTS and NETWORK_RETRY_DELAY_SECONDS config vars - Add retry_with_backoff helper function in kugetsu-config.sh - Replace subshell cd with git -C for safer directory handling
This commit is contained in:
@@ -26,6 +26,9 @@ QUEUE_DAEMON_INTERVAL_MINUTES="${QUEUE_DAEMON_INTERVAL_MINUTES:-5}"
|
||||
QUEUE_CLEANUP_AGE_DAYS="${QUEUE_CLEANUP_AGE_DAYS:-7}"
|
||||
TASK_TIMEOUT_HOURS="${TASK_TIMEOUT_HOURS:-1}"
|
||||
|
||||
NETWORK_RETRY_ATTEMPTS="${NETWORK_RETRY_ATTEMPTS:-3}"
|
||||
NETWORK_RETRY_DELAY_SECONDS="${NETWORK_RETRY_DELAY_SECONDS:-5}"
|
||||
|
||||
# Load user config overrides (~/.kugetsu/config)
|
||||
if [ -f "$KUGETSU_DIR/config" ]; then
|
||||
source "$KUGETSU_DIR/config"
|
||||
@@ -87,3 +90,24 @@ set_debug_mode() {
|
||||
|
||||
echo "${filtered_args[@]}"
|
||||
}
|
||||
|
||||
retry_with_backoff() {
|
||||
local max_attempts="${1:-$NETWORK_RETRY_ATTEMPTS}"
|
||||
local delay_seconds="${2:-$NETWORK_RETRY_DELAY_SECONDS}"
|
||||
local command="$3"
|
||||
local remaining_attempts=$max_attempts
|
||||
|
||||
while [ $remaining_attempts -gt 0 ]; do
|
||||
if eval "$command"; then
|
||||
return 0
|
||||
fi
|
||||
remaining_attempts=$((remaining_attempts - 1))
|
||||
if [ $remaining_attempts -gt 0 ]; then
|
||||
log "warn" "retry_with_backoff" "Command failed, $remaining_attempts retries remaining. Waiting ${delay_seconds}s..."
|
||||
sleep "$delay_seconds"
|
||||
delay_seconds=$((delay_seconds * 2))
|
||||
fi
|
||||
done
|
||||
log "error" "retry_with_backoff" "Command failed after $max_attempts attempts"
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user