{"record":{"id":"21fe565133684cad","repo":"petkaantonov/bluebird","slug":"cannot-get-rejection-reason-of-a-non-rejected-prom","errorCode":null,"errorMessage":"cannot get rejection reason of a non-rejected promise\n\n    See http://goo.gl/MqrFmX\n","messagePattern":"cannot get rejection reason of a non-rejected promise\n\n    See http://goo\\.gl/MqrFmX\n","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/synchronous_inspection.js","lineNumber":30,"sourceCode":"        this._settledValueField = undefined;\n    }\n}\n\nPromiseInspection.prototype._settledValue = function() {\n    return this._settledValueField;\n};\n\nvar value = PromiseInspection.prototype.value = function () {\n    if (!this.isFulfilled()) {\n        throw new TypeError(INSPECTION_VALUE_ERROR);\n    }\n    return this._settledValue();\n};\n\nvar reason = PromiseInspection.prototype.error =\nPromiseInspection.prototype.reason = function () {\n    if (!this.isRejected()) {\n        throw new TypeError(INSPECTION_REASON_ERROR);\n    }\n    return this._settledValue();\n};\n\nvar isFulfilled = PromiseInspection.prototype.isFulfilled = function() {\n    return (this._bitField & IS_FULFILLED) !== 0;\n};\n\nvar isRejected = PromiseInspection.prototype.isRejected = function () {\n    return (this._bitField & IS_REJECTED) !== 0;\n};\n\nvar isPending = PromiseInspection.prototype.isPending = function () {\n    return (this._bitField & IS_REJECTED_OR_FULFILLED_OR_CANCELLED) === 0;\n};\n\nvar isResolved = PromiseInspection.prototype.isResolved = function () {\n    return (this._bitField & IS_REJECTED_OR_FULFILLED) !== 0;","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/petkaantonov/bluebird/blob/c220cfe480868e2f5c5de4fe8bb3b04b97588d7f/src/synchronous_inspection.js#L12-L48","documentation":"The `.reason()`/`.error()` accessor on PromiseInspection (src/synchronous_inspection.js:30) returns the rejection reason only when the underlying promise is rejected. Calling it on a fulfilled or pending inspection throws this TypeError.","triggerScenarios":"`promise.reflect().then(insp => insp.reason())` when the promise fulfilled; calling `.reason()` on `Promise.inspect(p)` while p is still pending.","commonSituations":"Error-reporting pipelines over `allSettled`-style reflect results that unconditionally read `.reason()`; mixing up `.value()`/`.reason()` branches.","solutions":["Guard with `insp.isRejected()` before calling `.reason()`.","Branch symmetrically: `isFulfilled() ? insp.value() : insp.reason()`.","For aggregate reporting, normalize each inspection into a result object first."],"exampleFix":"// before\nresults.map(insp => insp.reason());\n// after\nresults.map(insp => insp.isRejected() ? insp.reason() : null);","handlingStrategy":"type-guard","validationCode":"const readReason = (insp) => {\n  if (!insp.isRejected()) throw new TypeError('reason() requires a rejected inspection');\n  return insp.reason();\n};","typeGuard":"const readIfRejected = (insp) => insp.isRejected() ? { rejected: true, reason: insp.reason() } : { rejected: false };","tryCatchPattern":"p.reflect().then(insp => {\n  let err;\n  try { err = insp.reason(); } catch (e) {\n    err = insp.isFulfilled() ? insp.value() : null;\n  }\n  return err;\n});","preventionTips":["Always gate .reason() behind isRejected().","Pair value()/reason() reads with matching state checks in reflect() handlers.","Normalize inspections into a discriminated result before consuming."],"tags":["typeerror","reflect","synchronous-inspection"],"backgroundTag":"promise-inspection-wrong-state","analyzedSha":"c220cfe480868e2f5c5de4fe8bb3b04b97588d7f","analyzedAt":"2026-09-02T02:30:20.863Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}