dianping/cat · error · Error
Please supply an object of options
Error message
Please supply an object of options
What it means
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.
Source
Thrown at cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js:137
for (k in obj) {
t ++;
}
return t;
}
function each(collection, iterator) {
var index = 0;
$.each(collection, function(key, value) {
iterator(key, value, index++);
});
}
function sanitize(options) {
var buttons;
var total;
if (typeof options !== "object") {
throw new Error("Please supply an object of options");
}
if (!options.message) {
throw new Error("Please specify a message");
}
// make sure any supplied options take precedence over defaults
options = $.extend({}, defaults, options);
if (!options.buttons) {
options.buttons = {};
}
// we only support Bootstrap's "static" and false backdrop args
// supporting true would mean you could dismiss the dialog without
// explicitly interacting with it
options.backdrop = options.backdrop ? "static" : false;
View on GitHub (pinned to e815e74d4c)
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.
Example fix
// before
bootbox.dialog('Record saved');
// after
bootbox.dialog({ message: 'Record saved', buttons: { ok: { label: 'Close' } } });
// or simply:
bootbox.alert('Record saved'); Defensive patterns
Strategy: type-guard
Validate before calling
function toBootboxOptions(opts) {
if (typeof opts === 'string') return { message: opts };
if (opts && typeof opts === 'object') return opts;
throw new Error('bootbox options invalid: ' + typeof opts);
}
bootbox.dialog(toBootboxOptions(userInput)); Type guard
function isBootboxOptions(o) {
return o !== null && typeof o === 'object';
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- button key {key} is not allowed (options are {buttons})
- Please specify a message
- button with key {key} must be an object
- Invalid argument length
- alert requires callback property to be a function when provi
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/fb7bad3ae0f1a326.
Report an issue: GitHub.