Skip to content

Commit bacdf79

Browse files
committed
Address review comments
1 parent 3372fb9 commit bacdf79

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

internal/error_test.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"testing"
3131
"time"
3232

33+
"github.com/nexus-rpc/sdk-go/nexus"
3334
"github.com/stretchr/testify/assert"
3435
"github.com/stretchr/testify/require"
3536
commandpb "go.temporal.io/api/command/v1"
@@ -1021,7 +1022,34 @@ func Test_convertErrorToFailure_ChildWorkflowExecutionError(t *testing.T) {
10211022
require.Equal(err.startedEventID, childWorkflowExecutionErr.startedEventID)
10221023
}
10231024

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) {
10251053
require := require.New(t)
10261054
fc := GetDefaultFailureConverter()
10271055

temporalnexus/token.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const (
3737

3838
// workflowRunOperationToken is the decoded form of the workflow run operation token.
3939
type workflowRunOperationToken struct {
40+
// Version of the token, by default we assume we're on version 1, this field is not emitted as part of the output,
41+
// it's only used to reject newer token versions on load.
42+
Version int `json:"v"`
4043
// Type of the operation. Must be operationTypeWorkflowRun.
4144
Type operationTokenType `json:"t"`
4245
NamespaceName string `json:"ns"`
@@ -71,6 +74,9 @@ func loadWorkflowRunOperationToken(data string) (workflowRunOperationToken, erro
7174
if token.Type != operationTokenTypeWorkflowRun {
7275
return token, fmt.Errorf("invalid workflow token type: %v, expected: %v", token.Type, operationTokenTypeWorkflowRun)
7376
}
77+
if token.Version != 0 {
78+
return token, fmt.Errorf(`invalid workflow run token: "v" field should not be present`)
79+
}
7480
if token.WorkflowID == "" {
7581
return token, errors.New("invalid workflow run token: missing workflow ID (wid)")
7682
}

temporalnexus/token_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ func TestDecodeWorkflowRunOperationTokenErrors(t *testing.T) {
6262
missingWIDToken := base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString([]byte(`{"t":1}`))
6363
_, err = loadWorkflowRunOperationToken(missingWIDToken)
6464
require.ErrorContains(t, err, "invalid workflow run token: missing workflow ID (wid)")
65+
66+
versionedToken := base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString([]byte(`{"v":1, "t":1,"wid": "workflow-id"}`))
67+
_, err = loadWorkflowRunOperationToken(versionedToken)
68+
require.ErrorContains(t, err, `invalid workflow run token: "v" field should not be present`)
6569
}

0 commit comments

Comments
 (0)