Skip to content

Commit b9f8903

Browse files
Relax ErrorDetailsValues types matching (#1005)
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.
1 parent 4abefdd commit b9f8903

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

internal/error_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,21 @@ type testStruct2 struct {
4747
Favorites *[]string
4848
}
4949

50+
type testErrorStruct struct {
51+
message string
52+
}
53+
5054
var (
5155
testErrorDetails1 = "my details"
5256
testErrorDetails2 = 123
5357
testErrorDetails3 = testStruct{"a string", 321}
5458
testErrorDetails4 = testStruct2{"a string", 321, &[]string{"eat", "code"}}
5559
)
5660

61+
func (tes *testErrorStruct) Error() string{
62+
return tes.message
63+
}
64+
5765
func Test_GenericError(t *testing.T) {
5866
// test activity error
5967
errorActivityFn := func() error {
@@ -411,6 +419,14 @@ func TestErrorDetailsValues_WrongDecodedType(t *testing.T) {
411419
require.Error(t, err)
412420
}
413421

422+
func TestErrorDetailsValues_AssignableType(t *testing.T) {
423+
e := ErrorDetailsValues{&testErrorStruct{message: "my message"}}
424+
var errorOut error
425+
err := e.Get(&errorOut)
426+
require.NoError(t, err)
427+
require.Equal(t, "my message", errorOut.Error())
428+
}
429+
414430
func Test_SignalExternalWorkflowExecutionFailedError(t *testing.T) {
415431
context := &workflowEnvironmentImpl{
416432
decisionsHelper: newDecisionsHelper(),

internal/workflow_testsuite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (b ErrorDetailsValues) Get(valuePtr ...interface{}) error {
103103
for i, item := range valuePtr {
104104
target := reflect.ValueOf(item).Elem()
105105
val := reflect.ValueOf(b[i])
106-
if target.Type() != val.Type() {
106+
if !val.Type().AssignableTo(target.Type()) {
107107
return fmt.Errorf(
108108
"unable to decode argument: cannot set %v value to %v field", val.Type(), target.Type())
109109
}

0 commit comments

Comments
 (0)