···7070 line key description :: render_commands ~sub_level:(sub_level + 1) subs
7171 ;;
72727373+ (*handle exception from jj*)
7474+ let handle_jj_error error =
7575+ ui_state.show_prompt $= None;
7676+ ui_state.show_popup
7777+ $= Some
7878+ ( error
7979+ |> Jj_tui.AnsiReverse.colored_string
8080+ |> Ui.atom
8181+ |> Ui.resize ~sw:1 ~sh:1
8282+ |> Lwd.pure
8383+ , "An error occured running that command" );
8484+ ui_state.input $= `Mode (fun _ -> `Unhandled)
8585+ ;;
8686+8787+ (*catch any exceptions from jj*)
8888+ let safe_jj f = try f () with JJError error -> handle_jj_error error
8989+7390 let commands_list_ui commands =
7491 commands |> render_commands |> I.vcat |> Ui.atom |> Lwd.pure |> Wd.scroll_area
7592 ;;
···87104 , ""
88105 , function
89106 | `Finished str ->
9090- (match cmd with
9191- | `Cmd args ->
9292- let _result = jj (args @ [ str ]) in
9393- Global_funcs.update_status ();
9494- ()
9595- (* v_cmd_out $= jj (args @ [ str ]); *)
9696- | `Cmd_I args ->
9797- Lwd.set ui_state.view (`Cmd_I (args @ [ str ]))
9898- | `Fun func ->
9999- func str)
107107+ safe_jj (fun _ ->
108108+ match cmd with
109109+ | `Cmd args ->
110110+ let _result = jj (args @ [ str ]) in
111111+ Global_funcs.update_status ();
112112+ ()
113113+ (* v_cmd_out $= jj (args @ [ str ]); *)
114114+ | `Cmd_I args ->
115115+ Lwd.set ui_state.view (`Cmd_I (args @ [ str ]))
116116+ | `Fun func ->
117117+ func str)
100118 | `Closed ->
101119 () )
102120 in
···148166 | Handled ->
149167 if is_sub then ui_state.input $= `Normal;
150168 `Handled
169169+ | JJError error ->
170170+ handle_jj_error error;
171171+ `Unhandled
151172152173 and command_no_input description cmd =
153174 (* Use exceptions so we can break out of the list*)
+5-4
jj_tui/bin/jj_process.ml
···7575 res
7676 ;;
77777878+ exception JJError of string
7879 (** Run a jj command without outputting to the command_log.
7980 @param ?snapshot=true
8081 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
8182 @param ?color=true When true output will have terminal escape codes for color *)
8283 let jj_no_log ?(snapshot = true) ?(color = true) args =
8484+8385 match jj_no_log_errorable ~snapshot ~color args with
8486 | Ok a ->
8587 a
8688 | Error (`BadExit (code, str)) ->
8787- failwith (Printf.sprintf "Exited with code %i; Message:\n%s" code str)
8989+ raise (JJError (Printf.sprintf "Exited with code %i; Message:\n%s" code str))
8890 | Error (`EioErr a) ->
8989- failwith
9090- (Printf.sprintf
9191+ raise (JJError (Printf.sprintf
9192 "Error running jj process:\n%a"
9293 (fun _ -> Base.Error.to_string_hum)
9393- a)
9494+ a))
9495 ;;
95969697 let jj args =