petkaantonov/bluebird · error · TypeError

cannot get fulfillment value of a non-fulfilled promise

Error message

cannot get fulfillment value of a non-fulfilled promise

    See http://goo.gl/MqrFmX

What it means

The synchronous inspection API's `.value()` (src/synchronous_inspection.js:22) returns the fulfillment value only if the underlying promise is fulfilled. Calling it on a pending or rejected PromiseInspection throws this TypeError. Use `.isFulfilled()` first.

Source

Thrown at src/synchronous_inspection.js:22

    if (promise !== undefined) {
        promise = promise._target();
        this._bitField = promise._bitField;
        this._settledValueField = promise._isFateSealed()
            ? promise._settledValue() : undefined;
    }
    else {
        this._bitField = 0;
        this._settledValueField = undefined;
    }
}

PromiseInspection.prototype._settledValue = function() {
    return this._settledValueField;
};

var value = PromiseInspection.prototype.value = function () {
    if (!this.isFulfilled()) {
        throw new TypeError(INSPECTION_VALUE_ERROR);
    }
    return this._settledValue();
};

var reason = PromiseInspection.prototype.error =
PromiseInspection.prototype.reason = function () {
    if (!this.isRejected()) {
        throw new TypeError(INSPECTION_REASON_ERROR);
    }
    return this._settledValue();
};

var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
    return (this._bitField & IS_FULFILLED) !== 0;
};

var isRejected = PromiseInspection.prototype.isRejected = function () {
    return (this._bitField & IS_REJECTED) !== 0;

View on GitHub (pinned to c220cfe480)

Solutions

  1. Check `insp.isFulfilled()` before calling `.value()`; use `insp.reason()` otherwise.
  2. Use `insp.isRejected()` / `insp.isPending()` for explicit branching.
  3. In reflect-aggregation code, map each inspection to `{state, value|reason}`.

Example fix

// before
p.reflect().then(insp => console.log(insp.value()));
// after
p.reflect().then(insp => {
  if (insp.isFulfilled()) console.log(insp.value());
  else console.error(insp.reason());
});
Defensive patterns

Strategy: type-guard

Validate before calling

const readValue = (insp) => {
  if (!insp.isFulfilled()) throw new TypeError('value() requires a fulfilled inspection');
  return insp.value();
};

Type guard

const readIfFulfilled = (insp) => insp.isFulfilled() ? { ok: true, value: insp.value() } : { ok: false, reason: insp.isRejected() ? insp.reason() : null };

Try / catch

p.reflect().then(insp => {
  let out;
  try { out = insp.value(); } catch (e) {
    out = insp.isRejected() ? insp.reason() : null;
  }
  return out;
});

Prevention

When it happens

Trigger: `promise.reflect().then(insp => insp.value())` when the original promise rejected; `Promise.inspect(promise)` on a still-pending promise then calling `.value()` before settlement.

Common situations: reflect-based error aggregation where code reads `.value()` without branching on `isFulfilled()`; race-inspection patterns that assume fulfillment.

Related errors


AI-assisted analysis of petkaantonov/bluebird@c220cfe480 (2026-09-02). Data as JSON: /api/errors/2cb17f6fd824cd71. Report an issue: GitHub.