{"record":{"id":"7813b831bdc50162","repo":"dianping/cat","slug":"alert-requires-callback-property-to-be-a-function","errorCode":null,"errorMessage":"alert requires callback property to be a function when provided","messagePattern":"alert requires callback property to be a function when provided","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js","lineNumber":307,"sourceCode":"      allowedButtons[value] = true;\n    });\n\n    each(options.buttons, function(key) {\n      if (allowedButtons[key] === undefined) {\n        throw new Error(\"button key \" + key + \" is not allowed (options are \" + buttons.join(\"\\n\") + \")\");\n      }\n    });\n\n    return options;\n  }\n\n  exports.alert = function() {\n    var options;\n\n    options = mergeDialogOptions(\"alert\", [\"ok\"], [\"message\", \"callback\"], arguments);\n\n    if (options.callback && !$.isFunction(options.callback)) {\n      throw new Error(\"alert requires callback property to be a function when provided\");\n    }\n\n    /**\n     * overrides\n     */\n    options.buttons.ok.callback = options.onEscape = function() {\n      if ($.isFunction(options.callback)) {\n        return options.callback();\n      }\n      return true;\n    };\n\n    return exports.dialog(options);\n  };\n\n  exports.confirm = function() {\n    var options;\n","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js#L289-L325","documentation":"exports.alert validates that, if a callback is supplied, it is a function. alert is fire-and-forget — the callback (if any) is invoked when the dialog closes — so anything non-callable (string, number, object) is rejected rather than silently ignored.","triggerScenarios":"bootbox.alert('Done', 'refresh'); bootbox.alert('Done', {onClose: fn}); passing a variable that is undefined-checked but assigned a non-function; passing a method reference that failed to bind and came back as a string.","commonSituations":"Refactoring from a config-object style where callback lived inside an object; passing extra data as a second argument forgetting the second arg is the callback; minification/renaming that left the callback undefined-turned-string.","solutions":["Pass a function or omit the second argument entirely: bootbox.alert('Done'); bootbox.alert('Done', function(){ ... });","If you need to pass data, close over it: bootbox.alert('Done ' + name, function(){ refresh(name); }).","If wrapping alert dynamically, guard: typeof cb === 'function' ? bootbox.alert(m, cb) : bootbox.alert(m)."],"exampleFix":"// before\nbootbox.alert('Saved', { onClose: reloadList });\n\n// after\nbootbox.alert('Saved', reloadList);","handlingStrategy":"type-guard","validationCode":"bootbox.alert('Saved', typeof cb === 'function' ? cb : undefined);\n// undefined second arg is safely omitted by the wrapper","typeGuard":"function isOptionalCallback(cb) {\n  return cb === undefined || typeof cb === 'function';\n}","tryCatchPattern":null,"preventionTips":["alert's second argument is a function or nothing","Close over data instead of passing objects as callback","Guard dynamically supplied callbacks with typeof checks"],"tags":["bootbox","alert","callback","validation"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}