worktrunk
worktrunk copied to clipboard
wt switch panics when entering a non-existent branch name
When running wt switch, entering an invalid branch name (in interactive prompt) causes wt to panic instead of handling the missing selection gracefully.
export RUST_BACKTRACE=full
wt --version
wt v0.29.4
wt switch
thread 'main' panicked at src/commands/select/mod.rs:378:26:
skim accept has selection
stack backtrace:
0: 0x7f57642b2ad3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h22163504fb5617e8
1: 0x7f5763ff4b43 - core::fmt::write::h3404918778c56320
2: 0x7f57642ae203 - std::io::Write::write_fmt::h0068f6d6606bbd31
3: 0x7f57642b2932 - std::sys::backtrace::BacktraceLock::print::h0c3ce8819c04ce8e
4: 0x7f57642b57b9 - std::panicking::default_hook::{{closure}}::hef55dae88db84fca
5: 0x7f57642b5338 - std::panicking::default_hook::hb3b1526ebfff314d
6: 0x7f57642b5ee5 - std::panicking::rust_panic_with_hook::hea6ecb54676124a4
7: 0x7f57642b5caa - std::panicking::begin_panic_handler::{{closure}}::ha862ada03b6f6f37
8: 0x7f57642b2fa9 - std::sys::backtrace::__rust_end_short_backtrace::hf3b64ce931e01744
9: 0x7f57642b595d - __rustc[de2ca18b4c54d5b8]::rust_begin_unwind
10: 0x7f5763ebdba0 - core::panicking::panic_fmt::h33b9d570969ba308
11: 0x7f5763ebdb7b - core::option::expect_failed::hd92ffaeb6d766b3e
12: 0x7f57646d9d01 - wt::commands::select::handle_select::hba1da2d57a96a6c9
13: 0x7f576459590f - wt::handle_switch_command::h1045a521d54c9642
14: 0x7f5764598c4e - wt::main::h392e09ed50e8cb52
15: 0x7f5764657c93 - std::sys::backtrace::__rust_begin_short_backtrace::h092cf3cf68ea6b24
16: 0x7f5764690349 - std::rt::lang_start::{{closure}}::he6218263fc2e5af1
17: 0x7f57642a3b61 - std::rt::lang_start_internal::h5989575fd474840b
18: 0x7f576459b695 - main
Thanks for reporting this! I was able to identify the root cause: when the interactive picker has no matching items for the typed query, skim returns an empty selection, but the code used .expect() assuming a selection always exists.
I've opened #1566 with a fix that replaces the panic with a helpful error message guiding toward alt-c to create a new worktree. A maintainer will review it shortly.
thanks @dlnilsson !