@@ -18,7 +18,11 @@ import {
18
18
} from '../errors' ;
19
19
import type { JobModule , ExecutionContext } from '../types' ;
20
20
import { ModuleInfoMap } from '../modules/linker' ;
21
- import { checkAndClearNullState , nullState } from '../util/null-state' ;
21
+ import {
22
+ clearNullState ,
23
+ isNullState ,
24
+ createNullState ,
25
+ } from '../util/null-state' ;
22
26
23
27
export type ExecutionErrorWrapper = {
24
28
state : any ;
@@ -52,7 +56,7 @@ export default (
52
56
// Create the main reducer function
53
57
const reducer = ( execute || defaultExecute ) (
54
58
...operations . map ( ( op , idx ) =>
55
- wrapOperation ( op , logger , `${ idx + 1 } ` , opts . immutableState , ` ${ idx } ` )
59
+ wrapOperation ( op , logger , `${ idx + 1 } ` , opts . immutableState )
56
60
)
57
61
) ;
58
62
@@ -101,29 +105,25 @@ export const wrapOperation = (
101
105
fn : Operation ,
102
106
logger : Logger ,
103
107
name : string ,
104
- immutableState ?: boolean ,
105
- prevName ?: string
108
+ immutableState ?: boolean
106
109
) => {
107
110
return async ( state : State ) => {
108
111
logger . debug ( `Starting operation ${ name } ` ) ;
109
112
const start = new Date ( ) . getTime ( ) ;
110
- if ( checkAndClearNullState ( state ) ) {
111
- logger . warn ( `Operation ${ name } might fail!` ) ;
113
+ if ( isNullState ( state ) ) {
114
+ clearNullState ( state ) ;
112
115
logger . warn (
113
- `The previous operation ${ prevName } didn't return a state. did you forget ?`
116
+ `WARNING: No state was passed into operation ${ name } . Did the previous operation return state ?`
114
117
) ;
115
118
}
116
119
const newState = immutableState ? clone ( state ) : state ;
117
120
118
- if ( typeof fn !== 'function' ) {
119
- logger . warn ( `Are you sure ${ name } is an operation?` ) ;
120
- logger . debug ( `Operation ${ name } isn't a valid operation` ) ;
121
- const duration = printDuration ( new Date ( ) . getTime ( ) - start ) ;
122
- logger . debug ( `Operation ${ name } skipped in ${ duration } ` ) ;
123
- return newState ;
124
- }
121
+ let result = await fn ( newState ) ;
125
122
126
- const result = ( await fn ( newState ) ) || nullState ( ) ;
123
+ if ( ! result ) {
124
+ logger . debug ( `Warning: operation ${ name } did not return state` ) ;
125
+ result = createNullState ( ) ;
126
+ }
127
127
128
128
// TODO should we warn if an operation does not return state?
129
129
// the trick is saying WHICH operation without source mapping
0 commit comments