usebruno/bruno · error · Error

${callback} is not a function

Error message

${callback} is not a function

What it means

Thrown by req.onFail(callback) in BrunoRequest when the callback argument is truthy but not a function. The method at bruno-request.js:237-243 checks typeof callback === 'function' first; if it fails but the value is truthy (e.g., a string, object, or number), the error is thrown. A falsy value (undefined, null) is silently ignored.

Source

Thrown at packages/bruno-js/src/bruno-request.js:241

  setMaxRedirects(maxRedirects) {
    this.req.maxRedirects = maxRedirects;
  }

  getTimeout() {
    return this.req.timeout;
  }

  setTimeout(timeout) {
    this.timeout = timeout;
    this.req.timeout = timeout;
  }

  onFail(callback) {
    if (typeof callback === 'function') {
      this.req.onFailHandler = callback;
    } else if (callback) {
      throw new Error(`${callback} is not a function`);
    }
  }

  __safeParseJSON(str) {
    try {
      return JSON.parse(str);
    } catch (e) {
      return str;
    }
  }

  __safeStringifyJSON(obj) {
    try {
      return JSON.stringify(obj);
    } catch (e) {
      return obj;
    }
  }

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Pass an actual function reference, not a name string: req.onFail(myHandler) not req.onFail('myHandler').
  2. If calling onFail conditionally, only pass the argument when you have a function: if (handler) req.onFail(handler).
  3. Verify typeof handler === 'function' before passing.

Example fix

// before
req.onFail('handleError'); // string, not a function

// after
function handleError(err) {
  console.error(err);
}
req.onFail(handleError); // function reference
Defensive patterns

Strategy: type-guard

Validate before calling

function isFunction(val) {
  return typeof val === 'function';
}
// before calling: if (isFunction(callback)) req.onFail(callback);

Type guard

function isFunction(val) {
  return typeof val === 'function';
}

Try / catch

try {
  req.onFail(handler);
} catch (e) {
  if (e.message.includes('is not a function')) {
    console.error('onFail callback was not a function reference');
  }
}

Prevention

When it happens

Trigger: Calling req.onFail('myHandler') (string), req.onFail({ handler: fn }) (object), or req.onFail(42) (number). Passing a variable that was expected to be a function reference but is actually a string name or undefined-like wrapper.

Common situations: Passing a function name as a string instead of the function reference. Passing an object that wraps the callback. Destructuring a handler from a config object incorrectly so it resolves to a non-function.

Related errors


AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13). Data as JSON: /api/errors/34f633b4bbe89fe4. Report an issue: GitHub.