Skip to content

Commit 2fcf302

Browse files
committed
fix: improve error handling in launch and command scripts
- Enhanced error handling in `lib/launch.sh` to log warnings when failing to open the editor or start the AI tool. - Updated `lib/commands/clean.sh` to ensure the current branch retrieval does not fail the script execution. - Improved user feedback in `lib/commands/editor.sh` by logging warnings when the file browser fails to open. - Added local variables in `lib/commands/copy.sh` for better clarity and maintainability.
1 parent 847965e commit 2fcf302

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

lib/commands/clean.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ _clean_merged() {
4848
[ -d "$dir" ] || continue
4949

5050
local branch
51-
branch=$(current_branch "$dir")
51+
branch=$(current_branch "$dir") || true
5252

5353
if [ -z "$branch" ] || [ "$branch" = "(detached)" ]; then
5454
log_warn "Skipping $dir (detached HEAD)"

lib/commands/copy.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ cmd_copy() {
6565
log_error "No worktrees found"
6666
exit 1
6767
fi
68+
local _branch
6869
while IFS= read -r _branch; do
6970
[ -n "$_branch" ] && targets+=("$_branch")
7071
done <<< "$all_branches"
7172
fi
7273

7374
# Process each target
7475
local copied_any=0
76+
local target_id
7577
for target_id in "${targets[@]}"; do
7678
local dst_path dst_branch
7779
resolve_worktree "$target_id" "$repo_root" "$base_dir" "$prefix" || continue

lib/commands/editor.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ cmd_editor() {
2929
worktree_path="$_ctx_worktree_path"
3030

3131
if [ "$editor" = "none" ]; then
32-
open_in_gui "$worktree_path"
33-
log_info "Opened in file browser"
32+
if ! open_in_gui "$worktree_path"; then
33+
log_warn "Could not open file browser"
34+
else
35+
log_info "Opened in file browser"
36+
fi
3437
else
3538
_open_editor "$editor" "$worktree_path" || exit 1
3639
fi

lib/launch.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ _auto_launch_editor() {
3030
local editor
3131
editor=$(_cfg_editor_default)
3232
if [ "$editor" != "none" ]; then
33-
_open_editor "$editor" "$worktree_path"
33+
_open_editor "$editor" "$worktree_path" || log_warn "Failed to open editor"
3434
else
3535
if ! open_in_gui "$worktree_path"; then
3636
log_warn "Could not open file browser"
@@ -50,6 +50,6 @@ _auto_launch_ai() {
5050
else
5151
load_ai_adapter "$ai_tool" || return 1
5252
log_step "Starting $ai_tool..."
53-
ai_start "$worktree_path"
53+
ai_start "$worktree_path" || log_warn "Failed to start AI tool"
5454
fi
5555
}

0 commit comments

Comments
 (0)