@@ -72,11 +72,12 @@ function verifyStateShape(inputState, outputState, action) {
72
72
73
73
export default function combineReducers ( reducers ) {
74
74
var finalReducers = pick ( reducers , ( val ) => typeof val === 'function' ) ;
75
+ var sanityError ;
75
76
76
77
Object . keys ( finalReducers ) . forEach ( key => {
77
78
var reducer = finalReducers [ key ] ;
78
- if ( typeof reducer ( undefined , { type : ActionTypes . INIT } ) === 'undefined' ) {
79
- throw new Error (
79
+ if ( ! sanityError && typeof reducer ( undefined , { type : ActionTypes . INIT } ) === 'undefined' ) {
80
+ sanityError = new Error (
80
81
`Reducer "${ key } " returned undefined during initialization. ` +
81
82
`If the state passed to the reducer is undefined, you must ` +
82
83
`explicitly return the initial state. The initial state may ` +
@@ -85,8 +86,8 @@ export default function combineReducers(reducers) {
85
86
}
86
87
87
88
var type = Math . random ( ) . toString ( 36 ) . substring ( 7 ) . split ( '' ) . join ( '.' ) ;
88
- if ( typeof reducer ( undefined , { type } ) === 'undefined' ) {
89
- throw new Error (
89
+ if ( ! sanityError && typeof reducer ( undefined , { type } ) === 'undefined' ) {
90
+ sanityError = new Error (
90
91
`Reducer "${ key } " returned undefined when probed with a random type. ` +
91
92
`Don't try to handle ${ ActionTypes . INIT } or other actions in "redux/*" ` +
92
93
`namespace. They are considered private. Instead, you must return the ` +
@@ -100,6 +101,9 @@ export default function combineReducers(reducers) {
100
101
var defaultState = mapValues ( finalReducers , ( ) => undefined ) ;
101
102
102
103
return function combination ( state = defaultState , action ) {
104
+ if ( sanityError ) {
105
+ throw sanityError ;
106
+ }
103
107
var finalState = mapValues ( finalReducers , ( reducer , key ) => {
104
108
var newState = reducer ( state [ key ] , action ) ;
105
109
if ( typeof newState === 'undefined' ) {
0 commit comments