Atlas › Test

TestFailureConverter_HandlerError

Exact test identity: go.temporal.io/server/common/nexus/nexusrpc/TestFailureConverter_HandlerError

Package
go.temporal.io/server/common/nexus/nexusrpc
Suite / test hierarchy
TestFailureConverter_HandlerError
Test
TestFailureConverter_HandlerError
Introduced at
failure_converter.go ×2 Frontier kind: Joint frontier
Covered ranges
23
Covered lines
64
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/nexus/nexusrpc/failure_converter.go 64 covered LOC · 23 ranges

Open complete file

30 }
31
32 > func (e serializedHandlerError) RetryBehavior() nexus.HandlerErrorRetryBehavior { failure_converter.go
33 > if e.RetryableOverride == nil {
34 > return nexus.HandlerErrorRetryBehaviorUnspecified failure_converter.go
35 > }
36 if *e.RetryableOverride {
37 return nexus.HandlerErrorRetryBehaviorRetryable
46 // ErrorToFailure implements FailureConverter.
47 // nolint:revive // Keeping all of the logic together for readability, even if it means the function is long.
48 > func (e knownErrorFailureConverter) ErrorToFailure(err error) (nexus.Failure, error) { failure_converter.go
49 > if err == nil {
50 return nexus.Failure{}, nil
51 }
52 // NOTE: not using errors.Unwrap here we are intentionally only supporting unwrapping known errors.
53 > switch typedErr := err.(type) { failure_converter.go
54 > case *nexus.FailureError: failure_converter.go
55 > f := typedErr.Failure
56 > // FailureError is has both a Cause error and an underlying Failure Cause.
57 > // When instantiated directly, there are cases where only the Go error cause is set.
58 > // Preserve the embedded failure's cause, as the embedded failure is treated similarly to the OriginalFailure field for well-known other error types.
59 > if typedErr.Cause != nil && f.Cause == nil {
60 c, err := e.ErrorToFailure(typedErr.Cause)
61 if err != nil {
64 f.Cause = &c
65 }
66 > return f, nil failure_converter.go
67 > case *nexus.HandlerError: failure_converter.go
68 > if typedErr.OriginalFailure != nil {
69 > return *typedErr.OriginalFailure, nil failure_converter.go
70 > }
71 > data := serializedHandlerError{ failure_converter.go
72 > Type: string(typedErr.Type),
73 > RetryableOverride: retryBehaviorAsOptionalBool(typedErr),
74 > }
75 > var details []byte
76 > details, err := json.Marshal(data)
77 > if err != nil {
78 return nexus.Failure{}, err
79 }
80 > f := nexus.Failure{ failure_converter.go
81 > Message: typedErr.Message,
82 > StackTrace: typedErr.StackTrace,
83 > Metadata: map[string]string{
84 > "type": "nexus.HandlerError",
85 > },
86 > Details: details,
87 > }
88 >
89 > if typedErr.Cause != nil {
90 > c, err := e.ErrorToFailure(typedErr.Cause) failure_converter.go
91 > if err != nil {
92 return nexus.Failure{}, err
93 }
94 > f.Cause = &c failure_converter.go
95 }
96 > return f, nil failure_converter.go
97 case *nexus.OperationError:
98 if typedErr.OriginalFailure != nil {
132 // FailureToError implements FailureConverter.
133 // nolint:revive // Keeping all of the logic together for readability, even if it means the function is long.
134 > func (e knownErrorFailureConverter) FailureToError(f nexus.Failure) (error, error) { failure_converter.go
135 > if f.Metadata != nil {
136 > switch f.Metadata["type"] { failure_converter.go
137 > case "nexus.HandlerError": failure_converter.go
138 > var se serializedHandlerError
139 > err := json.Unmarshal(f.Details, &se)
140 > if err != nil {
141 return nil, fmt.Errorf("failed to deserialize HandlerError: %w", err)
142 }
143 > he := &nexus.HandlerError{ failure_converter.go
144 > Message: f.Message,
145 > StackTrace: f.StackTrace,
146 > Type: nexus.HandlerErrorType(se.Type),
147 > RetryBehavior: se.RetryBehavior(),
148 > OriginalFailure: &f,
149 > }
150 > if f.Cause != nil {
151 > he.Cause, err = e.FailureToError(*f.Cause) failure_converter.go
152 > if err != nil {
153 return nil, err
154 }
155 }
156 > return he, nil failure_converter.go
157 case "nexus.OperationError":
158 var se serializedOperationError
177 }
178 // Note that the original failure cause is retained on the FailureError's failure object.
179 > fe := &nexus.FailureError{Failure: f} failure_converter.go
180 > if f.Cause != nil {
181 c, err := e.FailureToError(*f.Cause)
182 if err != nil {
200 }
201
202 > func retryBehaviorAsOptionalBool(e *nexus.HandlerError) *bool { failure_converter.go
203 > // nolint:exhaustive // this is a simple optional boolean.
204 > switch e.RetryBehavior {
205 case nexus.HandlerErrorRetryBehaviorRetryable:
206 ret := true