Skip to content

Commit

Permalink
Relax ErrorDetailsValues types matching (#1005)
Browse files Browse the repository at this point in the history
Current checks is too strict, because it requires types to match
exactly to be assignable. Relax that, so that it can be assigned
to any matching interface.
  • Loading branch information
vytautas-karpavicius committed Jul 20, 2020
1 parent 0357ffa commit 1f29ced
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions internal/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ type testStruct2 struct {
Favorites *[]string
}

type testErrorStruct struct {
message string
}

var (
testErrorDetails1 = "my details"
testErrorDetails2 = 123
testErrorDetails3 = testStruct{"a string", 321}
testErrorDetails4 = testStruct2{"a string", 321, &[]string{"eat", "code"}}
)

func (tes *testErrorStruct) Error() string{
return tes.message
}

func Test_GenericError(t *testing.T) {
// test activity error
errorActivityFn := func() error {
Expand Down Expand Up @@ -411,6 +419,14 @@ func TestErrorDetailsValues_WrongDecodedType(t *testing.T) {
require.Error(t, err)
}

func TestErrorDetailsValues_AssignableType(t *testing.T) {
e := ErrorDetailsValues{&testErrorStruct{message: "my message"}}
var errorOut error
err := e.Get(&errorOut)
require.NoError(t, err)
require.Equal(t, "my message", errorOut.Error())
}

func Test_SignalExternalWorkflowExecutionFailedError(t *testing.T) {
context := &workflowEnvironmentImpl{
decisionsHelper: newDecisionsHelper(),
Expand Down
2 changes: 1 addition & 1 deletion internal/workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (b ErrorDetailsValues) Get(valuePtr ...interface{}) error {
for i, item := range valuePtr {
target := reflect.ValueOf(item).Elem()
val := reflect.ValueOf(b[i])
if target.Type() != val.Type() {
if !val.Type().AssignableTo(target.Type()) {
return fmt.Errorf(
"unable to decode argument: cannot set %v value to %v field", val.Type(), target.Type())
}
Expand Down

0 comments on commit 1f29ced

Please sign in to comment.