@@ -50,12 +50,14 @@ func runSwitch(cfg *config.Config) error {
5050 options [i ] = fmt .Sprintf ("%d. %s" , branchIdx + 1 , s .Branches [branchIdx ].Branch )
5151 }
5252
53- p := prompter .New (cfg .In , cfg .Out , cfg .Err )
54- selectFn := func (prompt , def string , opts []string ) (int , error ) {
55- return p .Select (prompt , def , opts )
56- }
53+ var selectFn func (prompt , def string , opts []string ) (int , error )
5754 if cfg .SelectFn != nil {
5855 selectFn = cfg .SelectFn
56+ } else {
57+ p := prompter .New (cfg .In , cfg .Out , cfg .Err )
58+ selectFn = func (prompt , def string , opts []string ) (int , error ) {
59+ return p .Select (prompt , def , opts )
60+ }
5961 }
6062
6163 selected , err := selectFn ("Select a branch in the stack to switch to:" , "" , options )
@@ -65,6 +67,12 @@ func runSwitch(cfg *config.Config) error {
6567 printInterrupt (cfg )
6668 return errInterrupt
6769 }
70+ cfg .Errorf ("failed to select branch: %v" , err )
71+ return ErrSilent
72+ }
73+
74+ if selected < 0 || selected >= n {
75+ cfg .Errorf ("invalid selection" )
6876 return ErrSilent
6977 }
7078
0 commit comments