Skip to content

Commit 3ff8147

Browse files
authored
Add stacktrace logging to debug bundle
- Add stacktrace logging - 29.1.0
2 parents 41de449 + 3ed9b2e commit 3ff8147

File tree

6 files changed

+67
-4
lines changed

6 files changed

+67
-4
lines changed

docs/api/included-bundles.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ It takes the following options (none are required):
1212

1313
- `logSelectors` (default: true): whether or not to log out selectors and their computed value with each action dispatch
1414
- `logState` (default: true): whether to log state after each dispatch
15+
- `logStackTraces` (default: true): whether to log stack traces with each dispatch
16+
- `stackTraceLimit` (default: 100): stack trace limit to set when logging stack traces
1517
- `actionFilter` (default: null): a function to call that determines whether or not to log an action (if debug is enabled). For example, if you want hide the `APP_IDLE` actions pass this: `(action) => action.type !== 'APP_IDLE'`
1618
- `enabled` (default: HAS_DEBUG_FLAG): explicitly enable/disable. This is helpful in node.js where there's no localStorage flag.
1719
- `ignoreActions` (default: []): an array of actions to ignore when logging.

docs/misc/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Change Log
22

3+
- `29.1.0` Log stacktraces in the debug bundle log output.
34
- `29.0.0` This release has some changes that are unlikely to be breaking, but for safety releasing as a major bump:
45
- Fixes a bug during `integrateBundles` calls where the new bundles' `init` functions would be called before the store reducer had been replaced; potentially causing the code in the `init` function to throw if it called a selector that depended on the new state. The `init` functions are now called as the final step in `integrateBundles` - this is unlikely to be a breaking but if you are using `integrateBundles` and `init` functions, verifying they are working as expected is advised.
56
- Adds an `allowMissing` option to `subsribeToSelectors`. If passed, you can now subscribe to selectors that don't yet exist without the `subscribeToSelectors` call throwing. If the selector is added later (via `integrateBundles`) then changes to that selector will be emitted to the callback as expected.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "redux-bundler",
33
"description": "Compose a Redux store out of smaller bundles of functionality.",
4-
"version": "29.0.0",
4+
"version": "29.1.0",
55
"author": "Henrik Joreteg <henrik@joreteg.com> (joreteg.com)",
66
"bugs": {
77
"url": "https://github.com/HenrikJoreteg/redux-bundler/issues"

src/bundles/create-debug-bundle.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ export default spec => {
1717
const defaultOpts = {
1818
logSelectors: true,
1919
logState: true,
20+
logStackTraces: true,
2021
enabled: HAS_DEBUG_FLAG,
21-
actionFilter: null
22+
actionFilter: null,
23+
stackTraceLimit: 100
2224
}
2325

2426
const opts = Object.assign({}, defaultOpts, spec)
2527

28+
const initialStackTraceLimit = Error.stackTraceLimit
29+
2630
return {
2731
name: 'debug',
2832
reducer: (state = opts.enabled, { type }) => {
@@ -42,6 +46,13 @@ export default spec => {
4246
localStorage.debug = true
4347
} catch (e) {}
4448
}
49+
if (
50+
opts.logStackTraces &&
51+
Error.stackTraceLimit === initialStackTraceLimit
52+
) {
53+
Error.stackTraceLimit = opts.stackTraceLimit
54+
}
55+
4556
dispatch({ type: ENABLE })
4657
},
4758
doDisableDebug:
@@ -52,6 +63,12 @@ export default spec => {
5263
delete localStorage.debug
5364
} catch (e) {}
5465
}
66+
if (
67+
opts.logStackTraces &&
68+
Error.stackTraceLimit === opts.stackTraceLimit
69+
) {
70+
Error.stackTraceLimit = initialStackTraceLimit
71+
}
5572
dispatch({ type: DISABLE })
5673
},
5774
selectIsDebug: state => state.debug,
@@ -70,6 +87,11 @@ export default spec => {
7087
opts.logState && console.debug('state:', store.getState())
7188
opts.logSelectors && store.doLogSelectors()
7289
store.doLogNextReaction && store.doLogNextReaction()
90+
if (opts.logStackTraces) {
91+
console.groupCollapsed('stack trace')
92+
console.trace()
93+
console.groupEnd('stack trace')
94+
}
7395
console.groupEnd(action.type)
7496

7597
return result

test/create-debug-bundle.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,41 @@ test('create debug bundle basics', t => {
1919
t.ok(store.doLogDebugSummary, 'exists')
2020
t.end()
2121
})
22+
23+
test('sets stack trace limit', t => {
24+
const store = composeBundlesRaw(
25+
createDebugBundle({
26+
stackTraceLimit: 50
27+
}),
28+
{
29+
name: 'other',
30+
doSomething: () => {},
31+
selectSomething: () => true,
32+
reactToSomething: () => {}
33+
}
34+
)()
35+
36+
const initialStackTraceLimit = Error.stackTraceLimit
37+
38+
store.doEnableDebug()
39+
40+
t.equal(Error.stackTraceLimit, 50, 'should set stack trace limit to 50')
41+
42+
store.doDisableDebug()
43+
44+
t.equal(
45+
Error.stackTraceLimit,
46+
initialStackTraceLimit,
47+
'should reset stack trace limit'
48+
)
49+
50+
// Should not override the stack trace limit if it has been set elsewhere to
51+
// something other than the default
52+
Error.stackTraceLimit = 123
53+
store.doEnableDebug()
54+
t.equal(Error.stackTraceLimit, 123, 'does not override limit if has been set')
55+
store.doDisableDebug()
56+
t.equal(Error.stackTraceLimit, 123, 'does not override limit if has been set')
57+
58+
t.end()
59+
})

0 commit comments

Comments
 (0)