Skip to content

Commit ed09cea

Browse files
committed
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.
1 parent e3283bd commit ed09cea

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

core/environment/utils.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ import (
2929
"encoding/json"
3030
"errors"
3131
"fmt"
32+
"os"
33+
"sort"
34+
3235
"github.com/AliceO2Group/Control/common/logger/infologger"
3336
pb "github.com/AliceO2Group/Control/common/protos"
3437
"github.com/AliceO2Group/Control/core/task"
3538
"github.com/AliceO2Group/Control/core/task/sm"
3639
"github.com/AliceO2Group/Control/core/workflow"
3740
"github.com/looplab/fsm"
38-
"os"
39-
"sort"
4041

4142
"github.com/AliceO2Group/Control/core/the"
4243
"gopkg.in/yaml.v3"
@@ -143,7 +144,7 @@ func newCriticalTasksErrorMessage(env *Environment) string {
143144
}
144145

145146
func handleFailedGoError(err error, env *Environment) {
146-
var invalidEventErr *fsm.InvalidEventError
147+
var invalidEventErr fsm.InvalidEventError
147148
if errors.As(err, &invalidEventErr) {
148149
// this case can occur if the environment is in either:
149150
// - ERROR (env already transitioned to ERROR for another reason)

core/environment/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var _ = Describe("handleFailedGoError", func() {
3636
env.Sm = fsm.NewFSM("DONE", fsm.Events{}, fsm.Callbacks{})
3737
Expect(env.Sm.Current()).To(Equal("DONE"))
3838

39-
handleFailedGoError(&fsm.InvalidEventError{Event: "GO_ERROR", State: "DONE"}, env)
39+
handleFailedGoError(fsm.InvalidEventError{Event: "GO_ERROR", State: "DONE"}, env)
4040
Expect(env.Sm.Current()).To(Equal("DONE"))
4141
})
4242

0 commit comments

Comments
 (0)