From ed09cea69c4163ffff2dce322cfe427b95d284cb Mon Sep 17 00:00:00 2001 From: Piotr Konopka Date: Fri, 31 Oct 2025 10:01:26 +0100 Subject: [PATCH] fix recognizing InvalidEventError in handleFailedGoError Fixing an issue caused by the fact that I have no idea what I'm doing in Go. fsm.InvalidEventError implements Error() with a value receiver, which actually allows to provide an error as a value or as a pointer. However, errors.As() is not smart about it and does not strip the type from references/pointers/etc, so the original version would work only with errors passed as pointers. This commit modifies the helper to work correctly with errors provided as values, which is the more natural way to use it. Unfortunately it is not possible to prevent a caller from passing an error pointer. Let's consider it as a part of OCTRL-1064. --- core/environment/utils.go | 7 ++++--- core/environment/utils_test.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/environment/utils.go b/core/environment/utils.go index b5367d24..f05c0e3c 100644 --- a/core/environment/utils.go +++ b/core/environment/utils.go @@ -29,14 +29,15 @@ import ( "encoding/json" "errors" "fmt" + "os" + "sort" + "github.com/AliceO2Group/Control/common/logger/infologger" pb "github.com/AliceO2Group/Control/common/protos" "github.com/AliceO2Group/Control/core/task" "github.com/AliceO2Group/Control/core/task/sm" "github.com/AliceO2Group/Control/core/workflow" "github.com/looplab/fsm" - "os" - "sort" "github.com/AliceO2Group/Control/core/the" "gopkg.in/yaml.v3" @@ -143,7 +144,7 @@ func newCriticalTasksErrorMessage(env *Environment) string { } func handleFailedGoError(err error, env *Environment) { - var invalidEventErr *fsm.InvalidEventError + var invalidEventErr fsm.InvalidEventError if errors.As(err, &invalidEventErr) { // this case can occur if the environment is in either: // - ERROR (env already transitioned to ERROR for another reason) diff --git a/core/environment/utils_test.go b/core/environment/utils_test.go index 24e205d3..035f361a 100644 --- a/core/environment/utils_test.go +++ b/core/environment/utils_test.go @@ -36,7 +36,7 @@ var _ = Describe("handleFailedGoError", func() { env.Sm = fsm.NewFSM("DONE", fsm.Events{}, fsm.Callbacks{}) Expect(env.Sm.Current()).To(Equal("DONE")) - handleFailedGoError(&fsm.InvalidEventError{Event: "GO_ERROR", State: "DONE"}, env) + handleFailedGoError(fsm.InvalidEventError{Event: "GO_ERROR", State: "DONE"}, env) Expect(env.Sm.Current()).To(Equal("DONE")) })