Skip to content

Commit 84482ec

Browse files
Move ErrorDetailsValues to error.go (#1008)
1 parent b9f8903 commit 84482ec

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

internal/error.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package internal
2424
import (
2525
"errors"
2626
"fmt"
27+
"reflect"
2728
"strings"
2829

2930
"go.uber.org/cadence/.gen/go/shared"
@@ -133,6 +134,9 @@ type (
133134

134135
// UnknownExternalWorkflowExecutionError can be returned when external workflow doesn't exist
135136
UnknownExternalWorkflowExecutionError struct{}
137+
138+
// ErrorDetailsValues is a type alias used hold error details objects.
139+
ErrorDetailsValues []interface{}
136140
)
137141

138142
const (
@@ -375,3 +379,28 @@ func newUnknownExternalWorkflowExecutionError() *UnknownExternalWorkflowExecutio
375379
func (e *UnknownExternalWorkflowExecutionError) Error() string {
376380
return "UnknownExternalWorkflowExecution"
377381
}
382+
383+
// HasValues return whether there are values.
384+
func (b ErrorDetailsValues) HasValues() bool {
385+
return b != nil && len(b) != 0
386+
}
387+
388+
// Get extract data from encoded data to desired value type. valuePtr is pointer to the actual value type.
389+
func (b ErrorDetailsValues) Get(valuePtr ...interface{}) error {
390+
if !b.HasValues() {
391+
return ErrNoData
392+
}
393+
if len(valuePtr) > len(b) {
394+
return ErrTooManyArg
395+
}
396+
for i, item := range valuePtr {
397+
target := reflect.ValueOf(item).Elem()
398+
val := reflect.ValueOf(b[i])
399+
if !val.Type().AssignableTo(target.Type()) {
400+
return fmt.Errorf(
401+
"unable to decode argument: cannot set %v value to %v field", val.Type(), target.Type())
402+
}
403+
target.Set(val)
404+
}
405+
return nil
406+
}

internal/workflow_testsuite.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ type (
4040
dataConverter DataConverter
4141
}
4242

43-
// ErrorDetailsValues is a type alias used hold error details objects.
44-
ErrorDetailsValues []interface{}
45-
4643
// WorkflowTestSuite is the test suite to run unit tests for workflow/activity.
4744
WorkflowTestSuite struct {
4845
logger *zap.Logger
@@ -92,31 +89,6 @@ func (b EncodedValues) HasValues() bool {
9289
return b.values != nil
9390
}
9491

95-
// Get extract data from encoded data to desired value type. valuePtr is pointer to the actual value type.
96-
func (b ErrorDetailsValues) Get(valuePtr ...interface{}) error {
97-
if !b.HasValues() {
98-
return ErrNoData
99-
}
100-
if len(valuePtr) > len(b) {
101-
return ErrTooManyArg
102-
}
103-
for i, item := range valuePtr {
104-
target := reflect.ValueOf(item).Elem()
105-
val := reflect.ValueOf(b[i])
106-
if !val.Type().AssignableTo(target.Type()) {
107-
return fmt.Errorf(
108-
"unable to decode argument: cannot set %v value to %v field", val.Type(), target.Type())
109-
}
110-
target.Set(val)
111-
}
112-
return nil
113-
}
114-
115-
// HasValues return whether there are values.
116-
func (b ErrorDetailsValues) HasValues() bool {
117-
return b != nil && len(b) != 0
118-
}
119-
12092
// NewTestWorkflowEnvironment creates a new instance of TestWorkflowEnvironment. Use the returned TestWorkflowEnvironment
12193
// to run your workflow in the test environment.
12294
func (s *WorkflowTestSuite) NewTestWorkflowEnvironment() *TestWorkflowEnvironment {

0 commit comments

Comments
 (0)