dianping/cat · error · Error
Invalid argument length
Error message
Invalid argument length
What it means
mapArguments converts the convenience argument forms of alert/confirm/prompt into a single options object. It accepts exactly 1 or 2 arguments: either (options) or (str/prim, callback). Zero arguments, or three or more, throw 'Invalid argument length' before any dialog is created.
Source
Thrown at cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js:207
return options;
}
/**
* map a flexible set of arguments into a single returned object
* if args.length is already one just return it, otherwise
* use the properties argument to map the unnamed args to
* object properties
* so in the latter case:
* mapArguments(["foo", $.noop], ["message", "callback"])
* -> { message: "foo", callback: $.noop }
*/
function mapArguments(args, properties) {
var argn = args.length;
var options = {};
if (argn < 1 || argn > 2) {
throw new Error("Invalid argument length");
}
if (argn === 2 || typeof args[0] === "string") {
options[properties[0]] = args[0];
options[properties[1]] = args[1];
} else {
options = args[0];
}
return options;
}
/**
* merge a set of default dialog options with user supplied arguments
*/
function mergeArguments(defaults, args, properties) {
return $.extend(
// deep mergeView on GitHub (pinned to e815e74d4c)
Solutions
- Pass at most (message, callback): bootbox.confirm('Proceed?', function(result){ ... }) — branch on the boolean result inside.
- Pass a single options object when you need more configuration: bootbox.confirm({message: '...', callback: fn, title: '...'}).
- If wrapping bootbox dynamically, normalize first: pick the first 1-2 meaningful args or build an options object yourself.
Example fix
// before
bootbox.confirm('Delete this record?', function () { remove(); }, function () {});
// after
bootbox.confirm('Delete this record?', function (result) { if (result) remove(); }); Defensive patterns
Strategy: validation
Validate before calling
function showConfirm(msg, cb) {
cb = typeof cb === 'function' ? cb : null;
if (cb) bootbox.confirm(msg, cb); else bootbox.confirm({message: msg});
}
// never forward raw arguments objects of unknown length Type guard
function isValidBootboxArgs(args) {
return args.length >= 1 && args.length <= 2 &&
(typeof args[0] === 'string' || (args[0] && typeof args[0] === 'object'));
} Prevention
- alert/confirm/prompt accept at most (text, callback)
- Build an options object when more configuration is needed
- Normalize before .apply-ing dynamic arguments
When it happens
Trigger: bootbox.alert() with no arguments; bootbox.confirm('Proceed?', yesFn, noFn) — confirm supports only one callback (both outcomes go through it); forwarding an arguments object or spread of unknown length into a bootbox wrapper: bootbox.alert.apply(null, args).
Common situations: Copy-pasting from a two-callback dialog API (jQuery UI, native confirm patterns) into bootbox; a wrapper function using .apply with caller-controlled args; forgetting the message argument in a cleanup/dead code path that still executes.
Related errors
- Please supply an object of options
- button key {key} is not allowed (options are {buttons})
- Please specify a message
- button with key {key} must be an object
- 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/6c9bc15c8cb960fd.
Report an issue: GitHub.