@@ -1208,25 +1208,21 @@ func RunAsStep[R any](ctx DBOSContext, fn Step[R], opts ...StepOption) (R, error
12081208 if result == nil {
12091209 return * new (R ), err
12101210 }
1211- // Decode the result directly into the target type
1212- // result can be either an encoded *string (from recorded output) or already decoded any (from step execution)
12131211 var typedResult R
1214- if encodedOutput , ok := result .(* string ); ok {
1215- // Result is encoded, decode directly into target type
1212+ // When the step is executed, the result is already decoded and should be directly convertible
1213+ if typedRes , ok := result .(R ); ok {
1214+ typedResult = typedRes
1215+ } else if encodedOutput , ok := result .(* string ); ok {
1216+ // If not it should be an encoded *string
12161217 var decodeErr error
12171218 typedResult , decodeErr = deserialize [R ](serializer , encodedOutput )
12181219 if decodeErr != nil {
1219- workflowID , _ := ctx . GetWorkflowID () // Must be within a workflow so we can ignore the error
1220+ workflowID , _ := GetWorkflowID (ctx ) // Must be within a workflow so we can ignore the error
12201221 return * new (R ), newWorkflowExecutionError (workflowID , fmt .Errorf ("decoding step result to expected type %T: %w" , * new (R ), decodeErr ))
12211222 }
12221223 } else {
1223- // Result is already decoded, type-assert
1224- var ok bool
1225- typedResult , ok = result .(R )
1226- if ! ok {
1227- workflowID , _ := ctx .GetWorkflowID () // Must be within a workflow so we can ignore the error
1228- return * new (R ), newWorkflowUnexpectedResultType (workflowID , fmt .Sprintf ("%T" , * new (R )), fmt .Sprintf ("%T" , result ))
1229- }
1224+ workflowID , _ := GetWorkflowID (ctx ) // Must be within a workflow so we can ignore the error
1225+ return * new (R ), newWorkflowUnexpectedResultType (workflowID , fmt .Sprintf ("%T" , * new (R )), fmt .Sprintf ("%T" , result ))
12301226 }
12311227 return typedResult , err
12321228}
0 commit comments