{"record":{"id":"fb7bad3ae0f1a326","repo":"dianping/cat","slug":"please-supply-an-object-of-options","errorCode":null,"errorMessage":"Please supply an object of options","messagePattern":"Please supply an object of options","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js","lineNumber":137,"sourceCode":"    for (k in obj) {\n      t ++;\n    }\n    return t;\n  }\n\n  function each(collection, iterator) {\n    var index = 0;\n    $.each(collection, function(key, value) {\n      iterator(key, value, index++);\n    });\n  }\n\n  function sanitize(options) {\n    var buttons;\n    var total;\n\n    if (typeof options !== \"object\") {\n      throw new Error(\"Please supply an object of options\");\n    }\n\n    if (!options.message) {\n      throw new Error(\"Please specify a message\");\n    }\n\n    // make sure any supplied options take precedence over defaults\n    options = $.extend({}, defaults, options);\n\n    if (!options.buttons) {\n      options.buttons = {};\n    }\n\n    // we only support Bootstrap's \"static\" and false backdrop args\n    // supporting true would mean you could dismiss the dialog without\n    // explicitly interacting with it\n    options.backdrop = options.backdrop ? \"static\" : false;\n","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js#L119-L155","documentation":"bootbox's sanitize() is the entry validation for every dialog (dialog, alert, confirm, prompt). It requires the effective options to be an object; the alert/confirm/prompt wrappers convert (message, callback) argument forms into an options object via mapArguments, but bootbox.dialog() has no such conversion, so a non-object passed straight to dialog() hits this throw.","triggerScenarios":"bootbox.dialog('just a string'); bootbox.dialog(null); calling a wrapper with three arguments so argument mapping fails and a raw value leaks through; passing a jQuery object or a serialized JSON string instead of an options object.","commonSituations":"Migrating code from alert() convenience calls to the full dialog() API and forgetting dialog() needs {message: ...}; passing server-rendered JSON (a string) without JSON.parse; a wrapper function forwarding arguments incorrectly.","solutions":["Call bootbox.dialog with an options object: bootbox.dialog({message: '...', title: '...'}).","For simple message dialogs, use bootbox.alert(message, callback) which accepts the string form.","If the options may come from an external source, parse/validate it before calling: typeof opts === 'object' && opts !== null."],"exampleFix":"// before\nbootbox.dialog('Record saved');\n\n// after\nbootbox.dialog({ message: 'Record saved', buttons: { ok: { label: 'Close' } } });\n// or simply:\nbootbox.alert('Record saved');","handlingStrategy":"type-guard","validationCode":"function toBootboxOptions(opts) {\n  if (typeof opts === 'string') return { message: opts };\n  if (opts && typeof opts === 'object') return opts;\n  throw new Error('bootbox options invalid: ' + typeof opts);\n}\nbootbox.dialog(toBootboxOptions(userInput));","typeGuard":"function isBootboxOptions(o) {\n  return o !== null && typeof o === 'object';\n}","tryCatchPattern":null,"preventionTips":["Use dialog() only with object literals","Use alert(msg) for the string convenience form","Parse JSON strings from the server before passing them to bootbox"],"tags":["bootbox","dialog","validation","api-misuse"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}