Skip to content

Commit f6c8fc5

Browse files
committed
type check + nits
1 parent 38aec11 commit f6c8fc5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

dbos/workflow.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,11 @@ func RunAsStep[P any, R any](ctx DBOSContext, fn GenericStepFunc[P, R], input P)
692692

693693
// Type-erase the function based on its actual type
694694
typeErasedFn := StepFunc(func(ctx context.Context, input any) (any, error) {
695-
return fn(ctx, input.(P))
695+
typedInput, ok := input.(P)
696+
if !ok {
697+
return nil, newStepExecutionError("", "", fmt.Sprintf("unexpected input type: expected %T, got %T", *new(P), input))
698+
}
699+
return fn(ctx, typedInput)
696700
})
697701

698702
typeErasedStepNameToStepName[runtime.FuncForPC(reflect.ValueOf(typeErasedFn).Pointer()).Name()] = runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
@@ -718,7 +722,7 @@ func RunAsStep[P any, R any](ctx DBOSContext, fn GenericStepFunc[P, R], input P)
718722

719723
func (c *dbosContext) RunAsStep(_ DBOSContext, fn StepFunc, input any) (any, error) {
720724
// Get workflow state from context
721-
wfState, ok := c.ctx.Value(workflowStateKey).(*workflowState)
725+
wfState, ok := c.Value(workflowStateKey).(*workflowState)
722726
if !ok || wfState == nil {
723727
// TODO: try to print step name
724728
return nil, newStepExecutionError("", "", "workflow state not found in context: are you running this step within a workflow?")
@@ -738,7 +742,7 @@ func (c *dbosContext) RunAsStep(_ DBOSContext, fn StepFunc, input any) (any, err
738742

739743
// If within a step, just run the function directly
740744
if wfState.isWithinStep {
741-
return fn(c.ctx, input)
745+
return fn(c, input)
742746
}
743747

744748
// Setup step state

0 commit comments

Comments
 (0)