From 3e4d79f5eeacd8ea5a18af28ece514795f3bbded Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 23 Mar 2026 21:51:31 +0200 Subject: internal/rpn: fix error handling, variable name validation, and locking issues - Use error wrapping with ErrVariableNotFound for consistent error checking - Add isValidVariableName() for comprehensive variable name validation - Fix race condition in ClearVariables() by clearing instead of replacing map - Eliminate double-locking in FormatVariables() with internal helper function --- internal/rpn/operations.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'internal/rpn/operations.go') diff --git a/internal/rpn/operations.go b/internal/rpn/operations.go index 1ebd78b..cab77db 100644 --- a/internal/rpn/operations.go +++ b/internal/rpn/operations.go @@ -419,7 +419,7 @@ func (o *Operations) UseVariable(stack *Stack, name string) error { val, exists := o.vars.GetVariable(name) if !exists { - return fmt.Errorf("undefined variable: %s", name) + return fmt.Errorf("%w: %s", ErrVariableNotFound, name) } stack.Push(val) @@ -435,7 +435,7 @@ func (o *Operations) DeleteVariable(name string) error { deleted := o.vars.DeleteVariable(name) if !deleted { - return fmt.Errorf("undefined variable: %s", name) + return fmt.Errorf("%w: %s", ErrVariableNotFound, name) } return nil } -- cgit v1.2.3