@@ -143,4 +143,54 @@ setConfigEntry('hello', 'world').meta // {key: 'hello', domain: 'config'}
143143forConfigDomain (setEntry (' hello' , ' world' )).meta // {key: 'hello', domain: 'config'}
144144```
145145
146+ ## fullStack(error: Error, wrapped?: (error: Error) => string): string
147+
148+ Errors thrown from the sub-reducers you pass to ` createReducer ` , ` composeReducers ` , 'prefixReducer', or sub-middleware
149+ you pass to ` createMiddleware ` or ` composeMiddleware ` normally don't include any information about where the associated
150+ call to ` createReducer ` etc. occurred, making debugging difficult. However, in dev mode, ` mindfront-redux-utils ` adds
151+ this info to the resulting reducers and middleware, and you can get it by calling ` fullStack ` , like so:
152+
153+ ``` js
154+ import {createReducer , fullStack } from ' ./src'
155+
156+ function hello () {
157+ throw new Error (" TEST" )
158+ }
159+ const r = createReducer ({hello})
160+
161+ try {
162+ r ({}, {type: ' hello' })
163+ } catch (e) {
164+ console .error (fullStack (e))
165+ }
166+ ```
167+
168+ Output:
169+ ```
170+ Error: TEST
171+ at hello (/Users/andy/redux-utils/temp.js:4:9)
172+ at result (/Users/andy/redux-utils/src/createReducer.js:19:24)
173+ at withCause (/Users/andy/redux-utils/src/addCreationStack.js:5:14)
174+ at Object.<anonymous> (/Users/andy/redux-utils/temp.js:9:3)
175+ at Module._compile (module.js:556:32)
176+ at loader (/Users/andy/redux-utils/node_modules/babel-register/lib/node.js:144:5)
177+ at Object.require.extensions.(anonymous function) [as .js] (/Users/andy/redux-utils/node_modules/babel-register/lib/node.js:154:7)
178+ at Module.load (module.js:473:32)
179+ at tryModuleLoad (module.js:432:12)
180+ at Function.Module._load (module.js:424:3)
181+ Caused by reducer created at:
182+ at addCreationStack (/Users/andy/redux-utils/src/addCreationStack.js:2:21)
183+ at createReducer (/Users/andy/redux-utils/src/createReducer.js:25:55)
184+ at Object.<anonymous> (/Users/andy/redux-utils/temp.js:6:11)
185+ at Module._compile (module.js:556:32)
186+ at loader (/Users/andy/redux-utils/node_modules/babel-register/lib/node.js:144:5)
187+ at Object.require.extensions.(anonymous function) [as .js] (/Users/andy/redux-utils/node_modules/babel-register/lib/node.js:154:7)
188+ at Module.load (module.js:473:32)
189+ at tryModuleLoad (module.js:432:12)
190+ at Function.Module._load (module.js:424:3)
191+ at Function.Module.runMain (module.js:590:10)
192+ ```
193+
194+ If you are using [ VError] ( https://github.com/joyent/node-verror ) , you may pass VError's ` fullStack ` function as the
195+ second argument to also include the cause chain from ` VError ` .
146196
0 commit comments