{"record":{"id":"e711942927a0d7d2","repo":"dianping/cat","slug":"prompt-requires-a-callback","errorCode":null,"errorMessage":"prompt requires a callback","messagePattern":"prompt requires a callback","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js","lineNumber":440,"sourceCode":"\n          each(checkedItems, function(_, item) {\n            value.push($(item).val());\n          });\n          break;\n      }\n\n      return options.callback(value);\n    };\n\n    options.show = false;\n\n    // prompt specific validation\n    if (!options.title) {\n      throw new Error(\"prompt requires a title\");\n    }\n\n    if (!$.isFunction(options.callback)) {\n      throw new Error(\"prompt requires a callback\");\n    }\n\n    if (!templates.inputs[options.inputType]) {\n      throw new Error(\"invalid prompt type\");\n    }\n\n    // create the input based on the supplied type\n    input = $(templates.inputs[options.inputType]);\n\n    switch (options.inputType) {\n      case \"text\":\n      case \"textarea\":\n      case \"email\":\n      case \"date\":\n      case \"time\":\n      case \"number\":\n      case \"password\":\n        input.val(options.value);","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js#L422-L458","documentation":"bootbox.prompt requires a callback function, mandatory for the same reason as confirm: the entered value is only delivered via callback (string, or false/null when cancelled/dismissed). Validation runs after the title check and throws when options.callback is missing or not a function.","triggerScenarios":"bootbox.prompt('Your name:'); bootbox.prompt('Your name:', 'save'); bootbox.prompt({title: 'Your name:'}) with no callback; passing an unbound method reference that is undefined.","commonSituations":"Assuming prompt returns the value synchronously (it does not — pre-bootbox-5 it returns a jQuery/XHR-like dialog object); refactoring that dropped the callback; mixing up argument order (callback first, title second).","solutions":["Pass a function as the second argument (or callback property): bootbox.prompt('Your name:', function(v){ ... }).","Handle cancellation inside the callback: result === false or null means dismissed — code accordingly.","Do not rely on the return value for the user input; capture it in the callback closure."],"exampleFix":"// before\nvar name = bootbox.prompt('Enter your name:'); // no callback, throws\n\n// after\nbootbox.prompt('Enter your name:', function (name) {\n  if (name === null) return; // dismissed\n  save(name);\n});","handlingStrategy":"type-guard","validationCode":"if (typeof cb !== 'function') cb = function () {};\nbootbox.prompt('Enter a value:', cb);","typeGuard":"function isPromptCallback(fn) {\n  return typeof fn === 'function';\n}","tryCatchPattern":null,"preventionTips":["prompt never returns the value synchronously — use the callback","Treat null/false callback results as dismissal","Always pass the callback as the second argument or callback property"],"tags":["bootbox","prompt","callback","required-field"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}