When enabling bluebird's long stack traces, the appended Caused By... gets removed and a confusing/misleading stacktrace is created. The resulting stacktrace is the first part of the nested error stacktrace plus the first few lines of the Caused By: stacktrace appended with no indication of start/stop of stacktraces (plus the From previous event: trace after). Likewise, if the error has been nested multiple times, all of the nested (Caused By:) stacks get chopped/appending to the first stack.
https://github.com/petkaantonov/bluebird/blob/fdd44ee3af6d4fc2570a0f877ca82805a477c6b8/src/debuggability.js#L554 is to blame. I was considering adding a bluebird option to opt out of it, but was curious if this was something you had encountered and worked around previously. The regex being used is /^\s*at\s*/, so prepending at i.e. at Caused by: ... is another possible workaround.
let Promise = require('bluebird')
const NestedError = require('nested-error-stacks')
const throwError = () => { return Promise.reject(new Error('some error')) }
;(async function () {
await throwError()
.catch(err => {
throw new NestedError('nested', err)
}).catch (err => console.log(`BLUEBIRD_DEBUG not set: ${err.stack}\n`))
process.env.BLUEBIRD_DEBUG = 1
delete require.cache[require.resolve('bluebird')]
Promise = require('bluebird')
await throwError()
.catch(err => {
throw new NestedError('nested', err)
}).catch(err => console.log(`BLUEBIRD_DEBUG=1: ${err.stack}\n`))
})()
/*
BLUEBIRD_DEBUG not set: NestedError: nested
at throwError.catch.err (/Users/james.beavers/repos/test/bluebirdStacks.js:10:11)
at tryCatcher (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromiseCtx (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/promise.js:606:10)
at Async._drainQueue (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/async.js:138:12)
at Async._drainQueues (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:800:20)
at tryOnImmediate (timers.js:762:5)
at processImmediate [as _immediateCallback] (timers.js:733:5)
Caused By: Error: some error
at throwError (/Users/james.beavers/repos/test/bluebirdStacks.js:4:50)
at /Users/james.beavers/repos/test/bluebirdStacks.js:8:9
at Object.<anonymous> (/Users/james.beavers/repos/test/bluebirdStacks.js:22:3)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
BLUEBIRD_DEBUG=1: NestedError: nested
at throwError.catch.err (/Users/james.beavers/repos/test/bluebirdStacks.js:19:11)
at runCallback (timers.js:800:20)
at tryOnImmediate (timers.js:762:5)
at processImmediate [as _immediateCallback] (timers.js:733:5)
at throwError (/Users/james.beavers/repos/test/bluebirdStacks.js:4:50)
at /Users/james.beavers/repos/test/bluebirdStacks.js:17:9
From previous event:
at /Users/james.beavers/repos/test/bluebirdStacks.js:18:9
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:169:7)
*/
After changing how stacks are combined: stack += '\nat Caused By: ' + nested.stack;, the result is:
BLUEBIRD_DEBUG not set: NestedError: nested
at throwError.catch.err (/Users/james.beavers/repos/test/bluebirdStacks.js:10:11)
at tryCatcher (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromiseCtx (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/promise.js:606:10)
at Async._drainQueue (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/async.js:138:12)
at Async._drainQueues (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/Users/james.beavers/repos/test/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:800:20)
at tryOnImmediate (timers.js:762:5)
at processImmediate [as _immediateCallback] (timers.js:733:5)
at Caused By: Error: some error
at throwError (/Users/james.beavers/repos/test/bluebirdStacks.js:4:50)
at /Users/james.beavers/repos/test/bluebirdStacks.js:8:9
at Object.<anonymous> (/Users/james.beavers/repos/test/bluebirdStacks.js:22:3)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
BLUEBIRD_DEBUG=1: NestedError: nested
at throwError.catch.err (/Users/james.beavers/repos/test/bluebirdStacks.js:19:11)
at runCallback (timers.js:800:20)
at tryOnImmediate (timers.js:762:5)
at processImmediate [as _immediateCallback] (timers.js:733:5)
at Caused By: Error: some error
at throwError (/Users/james.beavers/repos/test/bluebirdStacks.js:4:50)
at /Users/james.beavers/repos/test/bluebirdStacks.js:17:9
From previous event:
at /Users/james.beavers/repos/test/bluebirdStacks.js:18:9
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:169:7)
note: the shorter stacks are due to bluebird automatically trimming common ancestors, internal trace lines, etc, but those lines aren't very useful anyway.
FWIW, this isn't a problem with Q's longStackSupport.
I can open a PR to prepend at, but I assume that would lead to a major version bump and might not be the preferred approach. Getting an opt-out merged into bluebird and released would probably take a while. Do you have a preference @mdlavin, or any other alternative ideas?
When enabling bluebird's long stack traces, the appended
Caused By...gets removed and a confusing/misleading stacktrace is created. The resulting stacktrace is the first part of the nested error stacktrace plus the first few lines of theCaused By:stacktrace appended with no indication of start/stop of stacktraces (plus theFrom previous event:trace after). Likewise, if the error has been nested multiple times, all of the nested (Caused By:) stacks get chopped/appending to the first stack.https://github.com/petkaantonov/bluebird/blob/fdd44ee3af6d4fc2570a0f877ca82805a477c6b8/src/debuggability.js#L554 is to blame. I was considering adding a bluebird option to opt out of it, but was curious if this was something you had encountered and worked around previously. The regex being used is
/^\s*at\s*/, so prependingati.e.at Caused by: ...is another possible workaround.After changing how stacks are combined:
stack += '\nat Caused By: ' + nested.stack;, the result is:note: the shorter stacks are due to bluebird automatically trimming common ancestors, internal trace lines, etc, but those lines aren't very useful anyway.
FWIW, this isn't a problem with Q's longStackSupport.
I can open a PR to prepend
at, but I assume that would lead to a major version bump and might not be the preferred approach. Getting an opt-out merged into bluebird and released would probably take a while. Do you have a preference @mdlavin, or any other alternative ideas?