summaryrefslogtreecommitdiff
path: root/internal/repl
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-23 23:07:29 +0200
committerPaul Buetow <paul@buetow.org>2026-03-23 23:07:29 +0200
commit2f6229e16f99095f44901cd38a83b41deda3c164 (patch)
treef7d396a3d63c539a1cfdee3dfedc6e862b5868c4 /internal/repl
parentc48e1f21d284370e1b76a605fd9b16c46bf37853 (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.go8
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