@@ -30,6 +30,7 @@ import (
30
30
"testing"
31
31
"time"
32
32
33
+ "github.com/nexus-rpc/sdk-go/nexus"
33
34
"github.com/stretchr/testify/assert"
34
35
"github.com/stretchr/testify/require"
35
36
commandpb "go.temporal.io/api/command/v1"
@@ -1021,7 +1022,34 @@ func Test_convertErrorToFailure_ChildWorkflowExecutionError(t *testing.T) {
1021
1022
require .Equal (err .startedEventID , childWorkflowExecutionErr .startedEventID )
1022
1023
}
1023
1024
1024
- func Test_convertErrorToFailure_UnknowError (t * testing.T ) {
1025
+ func Test_convertErrorToFailure_NexusHandlerError (t * testing.T ) {
1026
+ require := require .New (t )
1027
+ fc := GetDefaultFailureConverter ()
1028
+
1029
+ f := fc .ErrorToFailure (& nexus.HandlerError {
1030
+ Type : nexus .HandlerErrorTypeInternal ,
1031
+ Cause : errors .New ("custom cause" ),
1032
+ RetryBehavior : nexus .HandlerErrorRetryBehaviorNonRetryable ,
1033
+ })
1034
+ require .Equal ("handler error (INTERNAL): custom cause" , f .GetMessage ())
1035
+ require .Equal (string (nexus .HandlerErrorTypeInternal ), f .GetNexusHandlerFailureInfo ().Type )
1036
+ require .Equal (enumspb .NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_NON_RETRYABLE , f .GetNexusHandlerFailureInfo ().RetryBehavior )
1037
+ require .Equal ("" , f .Cause .GetApplicationFailureInfo ().Type )
1038
+ require .Equal ("custom cause" , f .Cause .Message )
1039
+
1040
+ err := fc .FailureToError (f )
1041
+ var handlerErr * nexus.HandlerError
1042
+ require .ErrorAs (err , & handlerErr )
1043
+ require .Equal (nexus .HandlerErrorTypeInternal , handlerErr .Type )
1044
+ require .Equal (nexus .HandlerErrorRetryBehaviorNonRetryable , handlerErr .RetryBehavior )
1045
+ require .Equal ("handler error (INTERNAL): custom cause" , handlerErr .Error ())
1046
+
1047
+ var applicationErr * ApplicationError
1048
+ require .ErrorAs (handlerErr .Cause , & applicationErr )
1049
+ require .Equal ("custom cause" , applicationErr .Error ())
1050
+ }
1051
+
1052
+ func Test_convertErrorToFailure_UnknownError (t * testing.T ) {
1025
1053
require := require .New (t )
1026
1054
fc := GetDefaultFailureConverter ()
1027
1055
0 commit comments