From 83634ef20eddef943b83b82a445f45b85c183c42 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Mon, 4 Aug 2025 06:23:52 +0100 Subject: [PATCH] log exceptions that occur to a local file --- .gitignore | 1 + shell/gl-draw.sml | 4 +--- shell/update-thread.sml | 50 +++++++++++++++++++++++++++++++---------- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 41d11bd..6557513 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ shf shf-tests +exceptions.log diff --git a/shell/gl-draw.sml b/shell/gl-draw.sml index 3ae18aa..f773145 100644 --- a/shell/gl-draw.sml +++ b/shell/gl-draw.sml @@ -229,9 +229,7 @@ struct end fun yank (shellState: t, str) = - ( Glfw.setClipboardString (#window shellState, str); - shellState - ) + (Glfw.setClipboardString (#window shellState, str); shellState) fun consumeDrawEvent (shellState, msg) = let diff --git a/shell/update-thread.sml b/shell/update-thread.sml index f4d435b..1e08440 100644 --- a/shell/update-thread.sml +++ b/shell/update-thread.sml @@ -2,6 +2,7 @@ structure UpdateThread = struct open CML open MailboxType + open InputMsg fun sendMsg (msg, drawMailbox) = case msg of DRAW msg => Mailbox.send (drawMailbox, msg) @@ -14,21 +15,46 @@ struct end | [] => () + val textCommands = ref "" + + fun addTextCommand inputMsg = + case inputMsg of + CHAR_EVENT chr => + let + val chr = CharVector.fromList [chr] + val newInput = !textCommands ^ chr + in + textCommands := newInput + end + | _ => () + + fun handleException e = + let + (* print stack trace for debugging purposes, + * and then raise another exception to exit the program *) + val stackTrace = MLton.Exn.history e + val stackTrace = String.concatWith "\n" stackTrace + val () = print "ERROR:\n" + val () = print (stackTrace ^ "\n\n") + + val history = !textCommands ^ "\n\n" + val () = print ("HISTORY: " ^ history) + + val textOutput = stackTrace ^ "\n" ^ history + + val io = TextIO.openAppend "exceptions.log" + val () = TextIO.output (io, textOutput) + val () = TextIO.closeOut io + in + raise Empty + end + fun loop (app: AppType.app_type, inputMailbox, drawMailbox) = let val inputMsg = Mailbox.recv inputMailbox - val app = - AppUpdate.update (app, inputMsg) - handle e => - let - (* print stack trace for debugging purposes, - * and then raise another exception to exit the program *) - val stackTrace = MLton.Exn.history e - val stackTrace = String.concatWith "\n" stackTrace - val () = print (stackTrace ^ "\n") - in - raise Empty - end + val () = addTextCommand inputMsg + + val app = AppUpdate.update (app, inputMsg) handle e => handleException e val () = sendMsgs (#msgs app, drawMailbox) in