Skip to content

Commit 7043879

Browse files
authored
IWF-567: Add error details to events emitted (#552)
1 parent 325e7ca commit 7043879

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

service/client/cadence/client.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cadence
22

33
import (
44
"context"
5+
"encoding/json"
56
"errors"
67
"fmt"
78
"github.com/indeedeng/iwf/config"
@@ -91,8 +92,28 @@ func (t *cadenceClient) GetApplicationErrorDetails(err error, detailsPtr interfa
9192

9293
func (t *cadenceClient) GetApplicationErrorTypeAndDetails(err error) (string, string) {
9394
errType := t.GetApplicationErrorTypeIfIsApplicationError(err)
94-
// TODO: Error Details will be added under IWF-567
95-
return errType, ""
95+
96+
var errDetailsPtr interface{}
97+
var errDetails string
98+
99+
err2 := t.GetApplicationErrorDetails(err, &errDetailsPtr)
100+
if err2 != nil {
101+
errDetails = err2.Error()
102+
} else {
103+
errDetailsString, ok := errDetailsPtr.(string)
104+
if ok {
105+
errDetails = errDetailsString
106+
} else {
107+
// All other types, e.g. iwfidl.StateCompletionOutput, try to Marshal the object to JSON
108+
var err error
109+
jsonBytes, err := json.Marshal(errDetailsPtr)
110+
if err == nil {
111+
errDetails = string(jsonBytes)
112+
}
113+
}
114+
}
115+
116+
return errType, errDetails
96117
}
97118

98119
func NewCadenceClient(

service/client/temporal/client.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package temporal
22

33
import (
44
"context"
5+
"encoding/json"
56
"errors"
67
"fmt"
78
"github.com/google/uuid"
@@ -119,8 +120,28 @@ func (t *temporalClient) GetApplicationErrorDetails(err error, detailsPtr interf
119120

120121
func (t *temporalClient) GetApplicationErrorTypeAndDetails(err error) (string, string) {
121122
errType := t.GetApplicationErrorTypeIfIsApplicationError(err)
122-
// TODO: Error Details will be added under IWF-567
123-
return errType, ""
123+
124+
var errDetailsPtr interface{}
125+
var errDetails string
126+
127+
err2 := t.GetApplicationErrorDetails(err, &errDetailsPtr)
128+
if err2 != nil {
129+
errDetails = err2.Error()
130+
} else {
131+
errDetailsString, ok := errDetailsPtr.(string)
132+
if ok {
133+
errDetails = errDetailsString
134+
} else {
135+
// All other types, e.g. iwfidl.StateCompletionOutput, try to Marshal the object to JSON
136+
var err error
137+
jsonBytes, err := json.Marshal(errDetailsPtr)
138+
if err == nil {
139+
errDetails = string(jsonBytes)
140+
}
141+
}
142+
}
143+
144+
return errType, errDetails
124145
}
125146

126147
func (t *temporalClient) StartInterpreterWorkflow(

0 commit comments

Comments
 (0)