terminal user interface to jujutsu. Focused on speed and clarity
9
fork

Configure Feed

Select the types of activity you want to include in your feed.

better error handling for jj

+36 -14
+31 -10
jj_tui/bin/jj_commands.ml
··· 70 70 line key description :: render_commands ~sub_level:(sub_level + 1) subs 71 71 ;; 72 72 73 + (*handle exception from jj*) 74 + let handle_jj_error error = 75 + ui_state.show_prompt $= None; 76 + ui_state.show_popup 77 + $= Some 78 + ( error 79 + |> Jj_tui.AnsiReverse.colored_string 80 + |> Ui.atom 81 + |> Ui.resize ~sw:1 ~sh:1 82 + |> Lwd.pure 83 + , "An error occured running that command" ); 84 + ui_state.input $= `Mode (fun _ -> `Unhandled) 85 + ;; 86 + 87 + (*catch any exceptions from jj*) 88 + let safe_jj f = try f () with JJError error -> handle_jj_error error 89 + 73 90 let commands_list_ui commands = 74 91 commands |> render_commands |> I.vcat |> Ui.atom |> Lwd.pure |> Wd.scroll_area 75 92 ;; ··· 87 104 , "" 88 105 , function 89 106 | `Finished str -> 90 - (match cmd with 91 - | `Cmd args -> 92 - let _result = jj (args @ [ str ]) in 93 - Global_funcs.update_status (); 94 - () 95 - (* v_cmd_out $= jj (args @ [ str ]); *) 96 - | `Cmd_I args -> 97 - Lwd.set ui_state.view (`Cmd_I (args @ [ str ])) 98 - | `Fun func -> 99 - func str) 107 + safe_jj (fun _ -> 108 + match cmd with 109 + | `Cmd args -> 110 + let _result = jj (args @ [ str ]) in 111 + Global_funcs.update_status (); 112 + () 113 + (* v_cmd_out $= jj (args @ [ str ]); *) 114 + | `Cmd_I args -> 115 + Lwd.set ui_state.view (`Cmd_I (args @ [ str ])) 116 + | `Fun func -> 117 + func str) 100 118 | `Closed -> 101 119 () ) 102 120 in ··· 148 166 | Handled -> 149 167 if is_sub then ui_state.input $= `Normal; 150 168 `Handled 169 + | JJError error -> 170 + handle_jj_error error; 171 + `Unhandled 151 172 152 173 and command_no_input description cmd = 153 174 (* Use exceptions so we can break out of the list*)
+5 -4
jj_tui/bin/jj_process.ml
··· 75 75 res 76 76 ;; 77 77 78 + exception JJError of string 78 79 (** Run a jj command without outputting to the command_log. 79 80 @param ?snapshot=true 80 81 When true snapshots the state when running the command and also aquires a lock before running it. Set to false for commands you wish to run concurrently. like those for generating content in the UI 81 82 @param ?color=true When true output will have terminal escape codes for color *) 82 83 let jj_no_log ?(snapshot = true) ?(color = true) args = 84 + 83 85 match jj_no_log_errorable ~snapshot ~color args with 84 86 | Ok a -> 85 87 a 86 88 | Error (`BadExit (code, str)) -> 87 - failwith (Printf.sprintf "Exited with code %i; Message:\n%s" code str) 89 + raise (JJError (Printf.sprintf "Exited with code %i; Message:\n%s" code str)) 88 90 | Error (`EioErr a) -> 89 - failwith 90 - (Printf.sprintf 91 + raise (JJError (Printf.sprintf 91 92 "Error running jj process:\n%a" 92 93 (fun _ -> Base.Error.to_string_hum) 93 - a) 94 + a)) 94 95 ;; 95 96 96 97 let jj args =