{"record":{"id":"34f633b4bbe89fe4","repo":"usebruno/bruno","slug":"callback-is-not-a-function","errorCode":null,"errorMessage":"${callback} is not a function","messagePattern":"(.+?) is not a function","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-js/src/bruno-request.js","lineNumber":241,"sourceCode":"\n  setMaxRedirects(maxRedirects) {\n    this.req.maxRedirects = maxRedirects;\n  }\n\n  getTimeout() {\n    return this.req.timeout;\n  }\n\n  setTimeout(timeout) {\n    this.timeout = timeout;\n    this.req.timeout = timeout;\n  }\n\n  onFail(callback) {\n    if (typeof callback === 'function') {\n      this.req.onFailHandler = callback;\n    } else if (callback) {\n      throw new Error(`${callback} is not a function`);\n    }\n  }\n\n  __safeParseJSON(str) {\n    try {\n      return JSON.parse(str);\n    } catch (e) {\n      return str;\n    }\n  }\n\n  __safeStringifyJSON(obj) {\n    try {\n      return JSON.stringify(obj);\n    } catch (e) {\n      return obj;\n    }\n  }","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-js/src/bruno-request.js#L223-L259","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass an actual function reference, not a name string: req.onFail(myHandler) not req.onFail('myHandler').","If calling onFail conditionally, only pass the argument when you have a function: if (handler) req.onFail(handler).","Verify typeof handler === 'function' before passing."],"exampleFix":"// before\nreq.onFail('handleError'); // string, not a function\n\n// after\nfunction handleError(err) {\n  console.error(err);\n}\nreq.onFail(handleError); // function reference","handlingStrategy":"type-guard","validationCode":"function isFunction(val) {\n  return typeof val === 'function';\n}\n// before calling: if (isFunction(callback)) req.onFail(callback);","typeGuard":"function isFunction(val) {\n  return typeof val === 'function';\n}","tryCatchPattern":"try {\n  req.onFail(handler);\n} catch (e) {\n  if (e.message.includes('is not a function')) {\n    console.error('onFail callback was not a function reference');\n  }\n}","preventionTips":["Pass a function reference, not a function name string.","Verify typeof callback === 'function' before passing to onFail.","If calling onFail conditionally, only pass the argument when you have a function."],"tags":["request","callback","validation","onfail","type-error"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}