@@ -111,13 +111,13 @@ func newTestContext(t *testing.T, ctx context.Context) *testContext {
111
111
return tc
112
112
}
113
113
114
- func (tc * testContext ) newNexusClient (t * testing.T , service string ) * nexus.Client {
114
+ func (tc * testContext ) newNexusClient (t * testing.T , service string ) * nexus.HTTPClient {
115
115
httpClient := http.Client {
116
116
Transport : & http.Transport {
117
117
TLSClientConfig : tc .testConfig .TLS ,
118
118
},
119
119
}
120
- nc , err := nexus .NewClient (nexus.ClientOptions {
120
+ nc , err := nexus .NewHTTPClient (nexus.HTTPClientOptions {
121
121
BaseURL : tc .endpointBaseURL ,
122
122
Service : service ,
123
123
HTTPCaller : func (r * http.Request ) (* http.Response , error ) {
@@ -178,12 +178,7 @@ var syncOp = temporalnexus.NewSyncOperation("sync-op", func(ctx context.Context,
178
178
}
179
179
return s , nil
180
180
case "fail" :
181
- return "" , & nexus.UnsuccessfulOperationError {
182
- State : nexus .OperationStateFailed ,
183
- Failure : nexus.Failure {
184
- Message : "fail" ,
185
- },
186
- }
181
+ return "" , nexus .NewFailedOperationError (errors .New ("fail" ))
187
182
case "fmt-errorf" :
188
183
return "" , fmt .Errorf ("arbitrary error message" )
189
184
case "handlererror" :
@@ -256,7 +251,7 @@ func TestNexusSyncOperation(t *testing.T) {
256
251
var unsuccessfulOperationErr * nexus.UnsuccessfulOperationError
257
252
require .ErrorAs (t , err , & unsuccessfulOperationErr )
258
253
require .Equal (t , nexus .OperationStateFailed , unsuccessfulOperationErr .State )
259
- require .Equal (t , "fail" , unsuccessfulOperationErr .Failure . Message )
254
+ require .Equal (t , "fail" , unsuccessfulOperationErr .Cause . Error () )
260
255
261
256
require .EventuallyWithT (t , func (t * assert.CollectT ) {
262
257
tc .requireTimer (t , metrics .NexusTaskEndToEndLatency , service .Name , syncOp .Name ())
@@ -272,7 +267,7 @@ func TestNexusSyncOperation(t *testing.T) {
272
267
var handlerErr * nexus.HandlerError
273
268
require .ErrorAs (t , err , & handlerErr )
274
269
require .Equal (t , nexus .HandlerErrorTypeInternal , handlerErr .Type )
275
- require .Contains (t , handlerErr .Failure . Message , "arbitrary error message" )
270
+ require .Contains (t , handlerErr .Cause . Error () , "arbitrary error message" )
276
271
277
272
require .EventuallyWithT (t , func (t * assert.CollectT ) {
278
273
tc .requireTimer (t , metrics .NexusTaskEndToEndLatency , service .Name , syncOp .Name ())
@@ -287,7 +282,7 @@ func TestNexusSyncOperation(t *testing.T) {
287
282
var handlerErr * nexus.HandlerError
288
283
require .ErrorAs (t , err , & handlerErr )
289
284
require .Equal (t , nexus .HandlerErrorTypeBadRequest , handlerErr .Type )
290
- require .Contains (t , handlerErr .Failure . Message , "handlererror" )
285
+ require .Contains (t , handlerErr .Cause . Error () , "handlererror" )
291
286
292
287
require .EventuallyWithT (t , func (t * assert.CollectT ) {
293
288
tc .requireTimer (t , metrics .NexusTaskEndToEndLatency , service .Name , syncOp .Name ())
@@ -302,7 +297,7 @@ func TestNexusSyncOperation(t *testing.T) {
302
297
var handlerErr * nexus.HandlerError
303
298
require .ErrorAs (t , err , & handlerErr )
304
299
require .Equal (t , nexus .HandlerErrorTypeBadRequest , handlerErr .Type )
305
- require .Contains (t , handlerErr .Failure . Message , "faking workflow already started" )
300
+ require .Contains (t , handlerErr .Cause . Error () , "faking workflow already started" )
306
301
307
302
require .EventuallyWithT (t , func (t * assert.CollectT ) {
308
303
tc .requireTimer (t , metrics .NexusTaskEndToEndLatency , service .Name , syncOp .Name ())
@@ -317,7 +312,7 @@ func TestNexusSyncOperation(t *testing.T) {
317
312
var handlerErr * nexus.HandlerError
318
313
require .ErrorAs (t , err , & handlerErr )
319
314
require .Equal (t , nexus .HandlerErrorTypeInternal , handlerErr .Type )
320
- require .Contains (t , handlerErr .Failure . Message , "fake app error for test" )
315
+ require .Contains (t , handlerErr .Cause . Error () , "fake app error for test" )
321
316
322
317
require .EventuallyWithT (t , func (t * assert.CollectT ) {
323
318
tc .requireTimer (t , metrics .NexusTaskEndToEndLatency , service .Name , syncOp .Name ())
@@ -329,10 +324,10 @@ func TestNexusSyncOperation(t *testing.T) {
329
324
330
325
t .Run ("non-retryable-application-error" , func (t * testing.T ) {
331
326
_ , err := nexus .ExecuteOperation (ctx , nc , syncOp , "non-retryable-application-error" , nexus.ExecuteOperationOptions {})
332
- var handlerErr * nexus.HandlerError
333
- require .ErrorAs (t , err , & handlerErr )
334
- require .Equal (t , nexus .HandlerErrorTypeBadRequest , handlerErr . Type )
335
- require .Contains (t , handlerErr . Failure . Message , "fake app error for test" )
327
+ var opErr * nexus.UnsuccessfulOperationError
328
+ require .ErrorAs (t , err , & opErr )
329
+ require .Equal (t , nexus .OperationStateFailed , opErr . State )
330
+ require .Contains (t , opErr . Cause . Error () , "fake app error for test" )
336
331
337
332
require .EventuallyWithT (t , func (t * assert.CollectT ) {
338
333
tc .requireTimer (t , metrics .NexusTaskEndToEndLatency , service .Name , syncOp .Name ())
@@ -347,7 +342,7 @@ func TestNexusSyncOperation(t *testing.T) {
347
342
var handlerErr * nexus.HandlerError
348
343
require .ErrorAs (t , err , & handlerErr )
349
344
require .Equal (t , nexus .HandlerErrorTypeInternal , handlerErr .Type )
350
- require .Contains (t , handlerErr .Failure . Message , "panic: panic requested" )
345
+ require .Contains (t , handlerErr .Cause . Error () , "panic: panic requested" )
351
346
352
347
require .EventuallyWithT (t , func (t * assert.CollectT ) {
353
348
tc .requireTimer (t , metrics .NexusTaskEndToEndLatency , service .Name , syncOp .Name ())
@@ -427,16 +422,19 @@ func TestSyncOperationFromWorkflow(t *testing.T) {
427
422
switch outcome {
428
423
case "successful" :
429
424
return outcome , nil
430
- case "failed" :
431
- return "" , & nexus.UnsuccessfulOperationError {
432
- State : nexus .OperationStateFailed ,
433
- Failure : nexus.Failure {Message : "failed for test" },
425
+ case "failed-plain-error" :
426
+ return "" , nexus .NewFailedOperationError (errors .New ("failed for test" ))
427
+ case "failed-app-error" :
428
+ return "" , nexus .NewFailedOperationError (temporal .NewApplicationError ("failed with app error" , "TestType" , "foo" ))
429
+ case "handler-plain-error" :
430
+ return "" , nexus .HandlerErrorf (nexus .HandlerErrorTypeBadRequest , "bad request" )
431
+ case "handler-app-error" :
432
+ return "" , & nexus.HandlerError {
433
+ Type : nexus .HandlerErrorTypeBadRequest ,
434
+ Cause : temporal .NewApplicationError ("failed with app error" , "TestType" , "foo" ),
434
435
}
435
436
case "canceled" :
436
- return "" , & nexus.UnsuccessfulOperationError {
437
- State : nexus .OperationStateCanceled ,
438
- Failure : nexus.Failure {Message : "canceled for test" },
439
- }
437
+ return "" , nexus .NewCanceledOperationError (errors .New ("canceled for test" ))
440
438
default :
441
439
panic (fmt .Errorf ("unexpected outcome: %s" , outcome ))
442
440
}
@@ -483,13 +481,13 @@ func TestSyncOperationFromWorkflow(t *testing.T) {
483
481
require .NoError (t , run .Get (ctx , nil ))
484
482
})
485
483
486
- t .Run ("OpFailed " , func (t * testing.T ) {
484
+ t .Run ("OpFailedPlainError " , func (t * testing.T ) {
487
485
run , err := tc .client .ExecuteWorkflow (ctx , client.StartWorkflowOptions {
488
486
TaskQueue : tc .taskQueue ,
489
487
// The endpoint registry may take a bit to propagate to the history service, use a shorter workflow task
490
488
// timeout to speed up the attempts.
491
489
WorkflowTaskTimeout : time .Second ,
492
- }, wf , "failed" )
490
+ }, wf , "failed-plain-error " )
493
491
require .NoError (t , err )
494
492
var execErr * temporal.WorkflowExecutionError
495
493
err = run .Get (ctx , nil )
@@ -539,6 +537,8 @@ func TestAsyncOperationFromWorkflow(t *testing.T) {
539
537
return action , nil
540
538
case "fail" :
541
539
return "" , fmt .Errorf ("handler workflow failed in test" )
540
+ case "fail-app-error" :
541
+ return "" , temporal .NewApplicationError ("failed with app error" , "TestType" , "foo" )
542
542
case "wait-for-cancel" :
543
543
return "" , workflow .Await (ctx , func () bool { return false })
544
544
default :
@@ -825,19 +825,9 @@ func TestWorkflowTestSuite_NexusSyncOperation(t *testing.T) {
825
825
case "ok" :
826
826
return outcome , nil
827
827
case "failure" :
828
- return "" , & nexus.UnsuccessfulOperationError {
829
- State : nexus .OperationStateFailed ,
830
- Failure : nexus.Failure {
831
- Message : "test operation failed" ,
832
- },
833
- }
828
+ return "" , nexus .NewFailedOperationError (errors .New ("test operation failed" ))
834
829
case "handler-error" :
835
- return "" , & nexus.HandlerError {
836
- Type : nexus .HandlerErrorTypeBadRequest ,
837
- Failure : & nexus.Failure {
838
- Message : "test operation failed" ,
839
- },
840
- }
830
+ return "" , nexus .HandlerErrorf (nexus .HandlerErrorTypeBadRequest , "test operation failed" )
841
831
}
842
832
panic (fmt .Errorf ("invalid outcome: %q" , outcome ))
843
833
})
0 commit comments