@@ -40,10 +40,17 @@ type testStruct struct {
4040 Age int
4141}
4242
43+ type testStruct2 struct {
44+ Name string
45+ Age int
46+ Favorites * []string
47+ }
48+
4349var (
4450 testErrorDetails1 = "my details"
4551 testErrorDetails2 = 123
4652 testErrorDetails3 = testStruct {"a string" , 321 }
53+ testErrorDetails4 = testStruct2 {"a string" , 321 , & []string {"eat" , "code" }}
4754)
4855
4956func Test_GenericError (t * testing.T ) {
@@ -195,6 +202,81 @@ func Test_CustomError(t *testing.T) {
195202 require .Equal (t , testErrorDetails3 , b3 )
196203}
197204
205+ func Test_CustomError_Pointer (t * testing.T ) {
206+ a1 := testStruct2 {}
207+ err1 := NewCustomError (customErrReasonA , testErrorDetails4 )
208+ require .True (t , err1 .HasDetails ())
209+ err := err1 .Details (& a1 )
210+ require .NoError (t , err )
211+ require .Equal (t , testErrorDetails4 , a1 )
212+
213+ a2 := & testStruct2 {}
214+ err2 := NewCustomError (customErrReasonA , & testErrorDetails4 ) // // pointer in details
215+ require .True (t , err2 .HasDetails ())
216+ err = err2 .Details (& a2 )
217+ require .NoError (t , err )
218+ require .Equal (t , & testErrorDetails4 , a2 )
219+
220+ // test EncodedValues as Details
221+ errorActivityFn := func () error {
222+ return err1
223+ }
224+ RegisterActivity (errorActivityFn )
225+ s := & WorkflowTestSuite {}
226+ env := s .NewTestActivityEnvironment ()
227+ _ , err = env .ExecuteActivity (errorActivityFn )
228+ require .Error (t , err )
229+ err3 , ok := err .(* CustomError )
230+ require .True (t , ok )
231+ require .True (t , err3 .HasDetails ())
232+ b1 := testStruct2 {}
233+ require .NoError (t , err3 .Details (& b1 ))
234+ require .Equal (t , testErrorDetails4 , b1 )
235+
236+ errorActivityFn2 := func () error {
237+ return err2 // pointer in details
238+ }
239+ RegisterActivity (errorActivityFn2 )
240+ _ , err = env .ExecuteActivity (errorActivityFn2 )
241+ require .Error (t , err )
242+ err4 , ok := err .(* CustomError )
243+ require .True (t , ok )
244+ require .True (t , err4 .HasDetails ())
245+ b2 := & testStruct2 {}
246+ require .NoError (t , err4 .Details (& b2 ))
247+ require .Equal (t , & testErrorDetails4 , b2 )
248+
249+ // test workflow error
250+ errorWorkflowFn := func (ctx Context ) error {
251+ return err1
252+ }
253+ RegisterWorkflow (errorWorkflowFn )
254+ wfEnv := s .NewTestWorkflowEnvironment ()
255+ wfEnv .ExecuteWorkflow (errorWorkflowFn )
256+ err = wfEnv .GetWorkflowError ()
257+ require .Error (t , err )
258+ err5 , ok := err .(* CustomError )
259+ require .True (t , ok )
260+ require .True (t , err5 .HasDetails ())
261+ err5 .Details (& b1 )
262+ require .NoError (t , err5 .Details (& b1 ))
263+ require .Equal (t , testErrorDetails4 , b1 )
264+
265+ errorWorkflowFn2 := func (ctx Context ) error {
266+ return err2 // pointer in details
267+ }
268+ RegisterWorkflow (errorWorkflowFn2 )
269+ wfEnv .ExecuteWorkflow (errorWorkflowFn2 )
270+ err = wfEnv .GetWorkflowError ()
271+ require .Error (t , err )
272+ err6 , ok := err .(* CustomError )
273+ require .True (t , ok )
274+ require .True (t , err6 .HasDetails ())
275+ err6 .Details (& b2 )
276+ require .NoError (t , err6 .Details (& b2 ))
277+ require .Equal (t , & testErrorDetails4 , b2 )
278+ }
279+
198280func Test_CanceledError (t * testing.T ) {
199281 // test ErrorDetailValues as Details
200282 var a1 string
0 commit comments