Foundry376/Mailspring · error

You registered an "onBeforeUnload" callback that does not re

Error message

You registered an "onBeforeUnload" callback that does not return either exactly true or false. It returned ${returnValue}

What it means

Warning in WindowEventHandler.runUnloadCallbacks: a callback registered via onBeforeUnload returned a value other than exactly true or false. Return values like undefined or a promise break the quit-flow protocol — the callback is skipped for completion tracking, so the window may quit before async work finishes.

Source

Thrown at app/src/window-event-handler.ts:288

  }

  runUnloadCallbacks() {
    let hasReturned = false;

    let unloadCallbacksRunning = 0;
    const unloadCallbackComplete = () => {
      unloadCallbacksRunning -= 1;
      if (unloadCallbacksRunning === 0 && hasReturned) {
        this.runUnloadFinished();
      }
    };

    for (const callback of this.unloadCallbacks) {
      const returnValue = callback(unloadCallbackComplete);
      if (returnValue === false) {
        unloadCallbacksRunning += 1;
      } else if (returnValue !== true) {
        console.warn(
          `You registered an "onBeforeUnload" callback that does not return either exactly true or false. It returned ${returnValue}`,
          callback
        );
      }
    }

    // In Electron, returning false cancels the close.
    hasReturned = true;
    if (unloadCallbacksRunning === 0) {
      for (const callback of this.unloadCompleteCallbacks) {
        callback();
      }
      return true;
    }
    return false;
  }

  runUnloadFinished() {

View on GitHub (pinned to 648c685d60)

Solutions

  1. Fix the callback to return true synchronously (done) or false (defer) per the onBeforeUnload contract
  2. For async work, return false and invoke the provided completion callback when finished
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at app/src/window-event-handler.ts:288 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Foundry376/Mailspring@648c685d60 (2026-09-03). Data as JSON: /api/errors/f7549b779133814e. Report an issue: GitHub.