Skip to content

Commit

Permalink
Clean up exception handling and retry code
Browse files Browse the repository at this point in the history
Clean up the exception matching and retry handling code, to unify UI
termination and reduce code duplication.
  • Loading branch information
tleedjarv committed Apr 1, 2024
1 parent 4b091e2 commit 2741c3a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/uitext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,15 @@ let rec start interface =
from here onwards are treated as potentially temporary or recoverable.
The process does not have to exit if in repeat mode and can try again. *)
and start2 () =
let noRepeat =
Prefs.read Uicommon.repeat = `NoRepeat
|| Prefs.read Uicommon.runtests
|| Prefs.read Uicommon.testServer
in
let terminate () =
handleException Sys.Break;
exit Uicommon.fatalExit
in
begin try
Uicommon.connectRoots ~displayWaitMessage ();

Expand All @@ -1664,28 +1673,20 @@ and start2 () =
(* Put the terminal back in "sane" mode, if necessary, and quit. *)
restoreTerminal();
exit exitStatus

with
Sys.Break -> begin
(* If we've been killed, then die *)
handleException Sys.Break;
exit Uicommon.fatalExit
end
| e when breakRepeat e -> begin
| Sys.Break -> terminate ()
| e when noRepeat || breakRepeat e -> begin
handleException e;
exit Uicommon.fatalExit
end
| e -> begin
(* If any other bad thing happened and the -repeat preference is
set, then restart *)
handleException e;
if Prefs.read Uicommon.repeat = `NoRepeat
|| Prefs.read Uicommon.runtests then
exit Uicommon.fatalExit;

Util.msg "\nRestarting in 10 seconds...\n\n";
begin try interruptibleSleep 10 with Sys.Break -> exit Uicommon.fatalExit end;
if safeStopRequested () then exit Uicommon.fatalExit else start2 ()
begin try interruptibleSleep 10 with Sys.Break -> terminate () end;
if safeStopRequested () then terminate () else start2 ()
end
end

Expand Down

0 comments on commit 2741c3a

Please sign in to comment.