{"record":{"id":"f5801e1a83cae09b","repo":"dianping/cat","slug":"confirm-requires-a-callback","errorCode":null,"errorMessage":"confirm requires a callback","messagePattern":"confirm requires a callback","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js","lineNumber":341,"sourceCode":"  exports.confirm = function() {\n    var options;\n\n    options = mergeDialogOptions(\"confirm\", [\"cancel\", \"confirm\"], [\"message\", \"callback\"], arguments);\n\n    /**\n     * overrides; undo anything the user tried to set they shouldn't have\n     */\n    options.buttons.cancel.callback = options.onEscape = function() {\n      return options.callback(false);\n    };\n\n    options.buttons.confirm.callback = function() {\n      return options.callback(true);\n    };\n\n    // confirm specific validation\n    if (!$.isFunction(options.callback)) {\n      throw new Error(\"confirm requires a callback\");\n    }\n\n    return exports.dialog(options);\n  };\n\n  exports.prompt = function() {\n    var options;\n    var defaults;\n    var dialog;\n    var form;\n    var input;\n    var shouldShow;\n    var inputOptions;\n\n    // we have to create our form first otherwise\n    // its value is undefined when gearing up our options\n    // @TODO this could be solved by allowing message to\n    // be a function instead...","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js#L323-L359","documentation":"Unlike alert, bootbox.confirm requires a callback (it must be a function) because the dialog's whole purpose is reporting the user's choice: the callback receives true (confirm) or false (cancel/escape). With no callable callback the result would be unusable, so it throws before rendering.","triggerScenarios":"bootbox.confirm('Proceed?'); bootbox.confirm('Proceed?', 'handleIt'); bootbox.confirm({message: '...'}) with a missing or non-function callback property; passing a callback that a wrapper failed to forward.","commonSituations":"Copy-pasted an alert() call and changed only the message; refactoring removed the callback during cleanup; assuming the promise-style API of bootbox 5+ (which returns a promise and makes callback optional) while running bootbox 4.x where it is mandatory.","solutions":["Supply a function: bootbox.confirm('Proceed?', function(result){ if (result) doIt(); }).","Check the callback exists when it is dynamic: if (typeof cb === 'function') bootbox.confirm(msg, cb); else bootbox.alert(msg).","If upgrading to bootbox 5+, note confirm may be used promise-style — but verify the bundled version first."],"exampleFix":"// before\nbootbox.confirm('Delete item?'); // nothing happens with the answer\n\n// after\nbootbox.confirm('Delete item?', function (result) {\n  if (result) deleteItem();\n});","handlingStrategy":"type-guard","validationCode":"if (typeof onDecide !== 'function') {\n  throw new Error('caller must supply a decision handler');\n}\nbootbox.confirm(message, onDecide);","typeGuard":"function isConfirmCallback(fn) {\n  return typeof fn === 'function';\n}","tryCatchPattern":null,"preventionTips":["confirm always needs a function callback","Handle both true and false results inside the callback","Check the bootbox version: 5.x allows promise style, 4.x does not"],"tags":["bootbox","confirm","callback","required-field"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}