@@ -935,25 +935,25 @@ func RunAsStep[R any](ctx DBOSContext, fn GenericStepFunc[R]) (R, error) {
935935}
936936
937937func (c * dbosContext ) RunAsStep (_ DBOSContext , fn StepFunc ) (any , error ) {
938+ // Look up for step parameters in the context and set defaults
939+ params , ok := c .Value (StepParamsKey ).(* StepParams )
940+ if ! ok {
941+ params = nil
942+ }
943+ params = setStepParamDefaults (params , runtime .FuncForPC (reflect .ValueOf (fn ).Pointer ()).Name ())
944+
938945 // Get workflow state from context
939946 wfState , ok := c .Value (workflowStateKey ).(* workflowState )
940947 if ! ok || wfState == nil {
941948 // TODO: try to print step name
942- return nil , newStepExecutionError ("" , "" , "workflow state not found in context: are you running this step within a workflow?" )
949+ return nil , newStepExecutionError ("" , params . StepName , "workflow state not found in context: are you running this step within a workflow?" )
943950 }
944951
945952 // This should not happen when called from the package-level RunAsStep
946953 if fn == nil {
947- return nil , newStepExecutionError (wfState .workflowID , "" , "step function cannot be nil" )
954+ return nil , newStepExecutionError (wfState .workflowID , params . StepName , "step function cannot be nil" )
948955 }
949956
950- // Look up for step parameters in the context and set defaults
951- params , ok := c .Value (StepParamsKey ).(* StepParams )
952- if ! ok {
953- params = nil
954- }
955- params = setStepParamDefaults (params , runtime .FuncForPC (reflect .ValueOf (fn ).Pointer ()).Name ())
956-
957957 // If within a step, just run the function directly
958958 if wfState .isWithinStep {
959959 return fn (c )
0 commit comments