{"record":{"id":"a34fe6b345e38d2f","repo":"petkaantonov/bluebird","slug":"cannot-enable-long-stack-traces-after-promises-hav","errorCode":null,"errorMessage":"cannot enable long stack traces after promises have been created\n\n    See http://goo.gl/MqrFmX\n","messagePattern":"cannot enable long stack traces after promises have been created\n\n    See http://goo\\.gl/MqrFmX\n","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/debuggability.js","lineNumber":144,"sourceCode":"\nPromise.prototype._warn = function(message, shouldUseOwnTrace, promise) {\n    return warn(message, shouldUseOwnTrace, promise || this);\n};\n\nPromise.onPossiblyUnhandledRejection = function (fn) {\n    var context = Promise._getContext();\n    possiblyUnhandledRejection = util.contextBind(context, fn);\n};\n\nPromise.onUnhandledRejectionHandled = function (fn) {\n    var context = Promise._getContext();\n    unhandledRejectionHandled = util.contextBind(context, fn);\n};\n\nvar disableLongStackTraces = function() {};\nPromise.longStackTraces = function () {\n    if (async.haveItemsQueued() && !config.longStackTraces) {\n        throw new Error(LONG_STACK_TRACES_ERROR);\n    }\n    if (!config.longStackTraces && longStackTracesIsSupported()) {\n        var Promise_captureStackTrace = Promise.prototype._captureStackTrace;\n        var Promise_attachExtraTrace = Promise.prototype._attachExtraTrace;\n        var Promise_dereferenceTrace = Promise.prototype._dereferenceTrace;\n        config.longStackTraces = true;\n        disableLongStackTraces = function() {\n            if (async.haveItemsQueued() && !config.longStackTraces) {\n                throw new Error(LONG_STACK_TRACES_ERROR);\n            }\n            Promise.prototype._captureStackTrace = Promise_captureStackTrace;\n            Promise.prototype._attachExtraTrace = Promise_attachExtraTrace;\n            Promise.prototype._dereferenceTrace = Promise_dereferenceTrace;\n            Context.deactivateLongStackTraces();\n            config.longStackTraces = false;\n        };\n        Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace;\n        Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace;","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/petkaantonov/bluebird/blob/c220cfe480868e2f5c5de4fe8bb3b04b97588d7f/src/debuggability.js#L126-L162","documentation":"Promise.longStackTraces() can only be enabled before any promise has been created/queued, because long-stack-trace instrumentation wraps core promise methods. If async.haveItemsQueued() reports pending work and long stack traces are not yet on, Bluebird throws this Error to avoid inconsistent instrumentation.","triggerScenarios":"Calling Promise.longStackTraces() (or setting config) after at least one promise has already been instantiated — e.g. enabling it inside application code that runs after module load, or in the middle of a running request handler instead of at process startup.","commonSituations":"Enabling longStackTraces in a middleware or lazy init path; requiring bluebird and creating promises before a config module runs; library code that creates a promise at import time, beating your configuration call.","solutions":["Call Promise.longStackTraces() as the very first thing after requiring bluebird, before any promise is created","Use the BLUEBIRD_DEBUG=1 / NODE_ENV=development environment variable which auto-enables long stack traces at load time","Pass longStackTraces via Promise.config({longStackTraces: true}) early at startup","Move the configuration out of lazy/deferred code paths to module initialization","Audit imports so no module creates a Bluebird promise before configuration"],"exampleFix":"// before\nconst app = require('./app'); // creates promises at import\nPromise.longStackTraces();\n// after\nconst Promise = require('bluebird');\nPromise.longStackTraces(); // before anything else\nconst app = require('./app');","handlingStrategy":"validation","validationCode":"const Promise = require('bluebird');\nif (!Promise.longStackTraces) return; // very old version\nPromise.longStackTraces(); // must run before any promise creation","typeGuard":"function canEnableLongStackTraces(Promise) {\n  try { Promise.longStackTraces(); return true; }\n  catch (e) { return false; }\n}","tryCatchPattern":"try {\n  Promise.longStackTraces();\n} catch (e) {\n  if (e.message.includes('long stack traces')) {\n    console.warn('longStackTraces enabled too late; set it at startup or use BLUEBIRD_DEBUG=1');\n  } else throw e;\n}","preventionTips":["Enable longStackTraces as the first statement after requiring bluebird","Use NODE_ENV=development or BLUEBIRD_DEBUG env vars instead of runtime calls","Never configure bluebird inside request handlers or lazy init","Ensure no module creates promises at import time before configuration"],"tags":["long-stack-traces","configuration","debuggability"],"backgroundTag":"long-stack-traces-too-late","analyzedSha":"c220cfe480868e2f5c5de4fe8bb3b04b97588d7f","analyzedAt":"2026-09-02T02:30:20.863Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}