fix(shell): address shellcheck warnings, standardize error handling, add retry logic #253

Merged
shoko merged 1 commits from fix/issue-121 into main 2026-04-08 07:04:26 +02:00
Owner

Summary

Fix shellcheck warnings and standardize error handling as requested in issue #121.

Changes

Shellcheck Warnings Fixed

  • SC2155: Separate variable assignment from declaration (local var=$(cmd)local var; var=$(cmd))
  • SC2166: Replace ! bool && bool pattern with explicit [ "\$bool" = true ] && [ "\$bool2" = true ]

Error Handling Standardization

  • All scripts use set -euo pipefail for consistent exit behavior
  • Functions that can fail either:
    • Exit immediately with set -e (for critical operations)
    • Return error code and log (for non-critical operations)
  • No more mixing of error handling strategies within the same function

Retry Logic Added

Added configurable retry logic for network operations:

git clone retry (in create_worktree):

  • Retries up to NETWORK_RETRY_ATTEMPTS times (default: 3)
  • Exponential backoff between attempts
  • Configurable via NETWORK_RETRY_DELAY_SECONDS (default: 5s)

opencode fork retry (in create_session):

  • Retries up to NETWORK_RETRY_ATTEMPTS times
  • Exponential backoff between attempts
  • Fails gracefully with proper error logging

New configuration variables:

NETWORK_RETRY_ATTEMPTS="${NETWORK_RETRY_ATTEMPTS:-3}"
NETWORK_RETRY_DELAY_SECONDS="${NETWORK_RETRY_DELAY_SECONDS:-5}"

Other Improvements

  • Replaced subshell cd with git -C for safer directory handling
  • Added retry_with_backoff helper function in kugetsu-config.sh

Backport Compatible

Yes - internal cleanup with stricter validation.

Acceptance Criteria

  • Zero shellcheck errors/warnings (where shellcheck is available)
  • Consistent error handling across modules
  • Network operations have retry logic (configurable attempts)

Closes #121

## Summary Fix shellcheck warnings and standardize error handling as requested in issue #121. ## Changes ### Shellcheck Warnings Fixed - **SC2155**: Separate variable assignment from declaration (`local var=$(cmd)` → `local var; var=$(cmd)`) - **SC2166**: Replace `! bool && bool` pattern with explicit `[ "\$bool" = true ] && [ "\$bool2" = true ]` ### Error Handling Standardization - All scripts use `set -euo pipefail` for consistent exit behavior - Functions that can fail either: - Exit immediately with `set -e` (for critical operations) - Return error code and log (for non-critical operations) - No more mixing of error handling strategies within the same function ### Retry Logic Added Added configurable retry logic for network operations: **git clone retry** (in `create_worktree`): - Retries up to `NETWORK_RETRY_ATTEMPTS` times (default: 3) - Exponential backoff between attempts - Configurable via `NETWORK_RETRY_DELAY_SECONDS` (default: 5s) **opencode fork retry** (in `create_session`): - Retries up to `NETWORK_RETRY_ATTEMPTS` times - Exponential backoff between attempts - Fails gracefully with proper error logging **New configuration variables**: ```bash NETWORK_RETRY_ATTEMPTS="${NETWORK_RETRY_ATTEMPTS:-3}" NETWORK_RETRY_DELAY_SECONDS="${NETWORK_RETRY_DELAY_SECONDS:-5}" ``` ### Other Improvements - Replaced subshell `cd` with `git -C` for safer directory handling - Added `retry_with_backoff` helper function in kugetsu-config.sh ## Backport Compatible Yes - internal cleanup with stricter validation. ## Acceptance Criteria - [x] Zero shellcheck errors/warnings (where shellcheck is available) - [x] Consistent error handling across modules - [x] Network operations have retry logic (configurable attempts) --- Closes #121
shoko added 1 commit 2026-04-08 06:47:49 +02:00
- 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
han approved these changes 2026-04-08 07:03:44 +02:00
han left a comment
First-time contributor

lgtm

lgtm
shoko merged commit ab99647193 into main 2026-04-08 07:04:26 +02:00
Sign in to join this conversation.