dianping/cat · error · Error
alert requires callback property to be a function when provi
Error message
alert requires callback property to be a function when provided
What it means
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.
Source
Thrown at cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js:307
allowedButtons[value] = true;
});
each(options.buttons, function(key) {
if (allowedButtons[key] === undefined) {
throw new Error("button key " + key + " is not allowed (options are " + buttons.join("\n") + ")");
}
});
return options;
}
exports.alert = function() {
var options;
options = mergeDialogOptions("alert", ["ok"], ["message", "callback"], arguments);
if (options.callback && !$.isFunction(options.callback)) {
throw new Error("alert requires callback property to be a function when provided");
}
/**
* overrides
*/
options.buttons.ok.callback = options.onEscape = function() {
if ($.isFunction(options.callback)) {
return options.callback();
}
return true;
};
return exports.dialog(options);
};
exports.confirm = function() {
var options;
View on GitHub (pinned to e815e74d4c)
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).
Example fix
// before
bootbox.alert('Saved', { onClose: reloadList });
// after
bootbox.alert('Saved', reloadList); Defensive patterns
Strategy: type-guard
Validate before calling
bootbox.alert('Saved', typeof cb === 'function' ? cb : undefined);
// undefined second arg is safely omitted by the wrapper Type guard
function isOptionalCallback(cb) {
return cb === undefined || typeof cb === 'function';
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Please supply an object of options
- Please specify a message
- button with key {key} must be an object
- button key {key} is not allowed (options are {buttons})
- confirm requires a callback
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/7813b831bdc50162.
Report an issue: GitHub.