Skip to content

Commit

Permalink
Dump all registered activities when activity not found (#437)
Browse files Browse the repository at this point in the history
This commit modifies task handler in the client SDK to dump all activities registered when a workflow executes an activity whose name is not found, for example, due to a typo when specifying the activity by name.
  • Loading branch information
arthurgan committed Apr 17, 2018
1 parent c0007b4 commit 72dadb9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
16 changes: 14 additions & 2 deletions internal/error_test.go
Expand Up @@ -22,11 +22,11 @@ package internal

import (
"errors"
"testing"

"fmt"
"github.com/stretchr/testify/require"
"go.uber.org/cadence/.gen/go/shared"
"go.uber.org/zap"
"testing"
)

const (
Expand Down Expand Up @@ -72,6 +72,18 @@ func Test_ActivityPanic(t *testing.T) {
require.Equal(t, "panic-blabla", panicErr.Error())
}

func Test_ActivityNotRegistered(t *testing.T) {
registeredActivityFn, unregisteredActivitFn := "RegisteredActivity", "UnregisteredActivityFn"
RegisterActivityWithOptions(func() error { return nil }, RegisterActivityOptions{Name: registeredActivityFn})
s := &WorkflowTestSuite{}
s.SetLogger(zap.NewNop())
env := s.NewTestActivityEnvironment()
_, err := env.ExecuteActivity(unregisteredActivitFn)
require.Error(t, err)
require.Contains(t, err.Error(), fmt.Sprintf("unable to find activityType=%v", unregisteredActivitFn))
require.Contains(t, err.Error(), registeredActivityFn)
}

func Test_WorkflowError(t *testing.T) {
errorWorkflowFn := func(ctx Context, i int) error {
return errs[i][0]
Expand Down
10 changes: 9 additions & 1 deletion internal/internal_task_handlers.go
Expand Up @@ -1240,7 +1240,8 @@ func (ath *activityTaskHandlerImpl) Execute(taskList string, t *s.PollForActivit
activityImplementation := ath.getActivity(activityType.GetName())
if activityImplementation == nil {
// Couldn't find the activity implementation.
return nil, fmt.Errorf("unable to find activityType=%v", activityType.GetName())
supported := strings.Join(ath.getRegisteredActivityNames(), ", ")
return nil, fmt.Errorf("unable to find activityType=%v. Supported types: [%v]", activityType.GetName(), supported)
}

// panic handler
Expand Down Expand Up @@ -1282,6 +1283,13 @@ func (ath *activityTaskHandlerImpl) getActivity(name string) activity {
return nil
}

func (ath *activityTaskHandlerImpl) getRegisteredActivityNames() (activityNames []string) {
for _, a := range ath.hostEnv.activityFuncMap {
activityNames = append(activityNames, a.ActivityType().Name)
}
return
}

func createNewDecision(decisionType s.DecisionType) *s.Decision {
return &s.Decision{
DecisionType: common.DecisionTypePtr(decisionType),
Expand Down
5 changes: 4 additions & 1 deletion internal/internal_workflow_testsuite.go
Expand Up @@ -407,8 +407,11 @@ func (env *testWorkflowEnvironmentImpl) executeActivity(
taskHandler := env.newTestActivityTaskHandler(defaultTestTaskList)
result, err := taskHandler.Execute(defaultTestTaskList, task)
if err != nil {
panic(err)
topLine := fmt.Sprintf("activity for %s [panic]:", defaultTestTaskList)
st := getStackTraceRaw(topLine, 7, 0)
return nil, newPanicError(err.Error(), st)
}

if result == ErrActivityResultPending {
return nil, ErrActivityResultPending
}
Expand Down

0 comments on commit 72dadb9

Please sign in to comment.