From 2f6229e16f99095f44901cd38a83b41deda3c164 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 23 Mar 2026 23:07:29 +0200 Subject: Add panic recovery to REPL executor for better resilience Added defer-recover mechanism to the executor function to catch unexpected panics. When a panic occurs, a user-friendly error message is displayed and the REPL can continue to function. This improves the robustness of the REPL when handling unexpected errors. --- internal/repl/repl.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'internal') diff --git a/internal/repl/repl.go b/internal/repl/repl.go index d903a90..ec5f245 100644 --- a/internal/repl/repl.go +++ b/internal/repl/repl.go @@ -99,6 +99,14 @@ func RunREPL() error { // executor runs a calculation command and returns the result func executor(input string) { + // Add panic recovery for better resilience + defer func() { + if r := recover(); r != nil { + fmt.Printf("Error: Unexpected error occurred: %v\n", r) + fmt.Println("Please try a different expression or command.") + } + }() + input = strings.TrimSpace(input) if input == "" { return -- cgit v1.2.3