diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-23 23:07:29 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-23 23:07:29 +0200 |
| commit | 2f6229e16f99095f44901cd38a83b41deda3c164 (patch) | |
| tree | f7d396a3d63c539a1cfdee3dfedc6e862b5868c4 /internal/repl | |
| parent | c48e1f21d284370e1b76a605fd9b16c46bf37853 (diff) | |
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.
Diffstat (limited to 'internal/repl')
| -rw-r--r-- | internal/repl/repl.go | 8 |
1 files changed, 8 insertions, 0 deletions
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 |
