dianping/cat · error · Error
given options in wrong format
Error message
given options in wrong format
What it means
While building select or radio prompt inputs, bootbox iterates inputOptions and requires every entry to be an object with both value and text properties; an entry missing either throws 'given options in wrong format'. The same check runs (on the first entry) for checkboxes. This prevents half-rendered option lists.
Source
Thrown at cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js:475
case "password":
input.val(options.value);
break;
case "select":
var groups = {};
inputOptions = options.inputOptions || [];
if (!inputOptions.length) {
throw new Error("prompt with select requires options");
}
each(inputOptions, function(_, option) {
// assume the element to attach to is the input...
var elem = input;
if (option.value === undefined || option.text === undefined) {
throw new Error("given options in wrong format");
}
// ... but override that element if this option sits in a group
if (option.group) {
// initialise group if necessary
if (!groups[option.group]) {
groups[option.group] = $("<optgroup/>").attr("label", option.group);
}
elem = groups[option.group];
}
elem.append("<option value='" + option.value + "'>" + option.text + "</option>");
});
each(groups, function(_, group) {View on GitHub (pinned to e815e74d4c)
Solutions
- Map every entry explicitly to {value: ..., text: ...}: items.map(function(i){ return {value: i.id, text: i.name}; }).
- Validate before the call: inputOptions.every(function(o){ return o && o.value !== undefined && o.text !== undefined; }).
- Skip or default malformed records during mapping (o.text = o.text || o.value) if partial data is acceptable.
Example fix
// before
inputOptions: response.users // [{id: 3, name: 'Ann'}, ...] -> throws
// after
inputOptions: response.users.map(function (u) {
return { value: u.id, text: u.name };
}) Defensive patterns
Strategy: validation
Validate before calling
function toInputOptions(rows) {
return rows.filter(function (r) { return r && r.id !== undefined && r.name !== undefined; })
.map(function (r) { return { value: r.id, text: r.name }; });
}
var opts = toInputOptions(rows);
if (opts.length) bootbox.prompt({ /* ... */ inputOptions: opts, callback: cb }); Type guard
function isWellFormedInputOption(o) {
return o !== null && typeof o === 'object' &&
o.value !== undefined && o.text !== undefined;
} Prevention
- Map API records to {value, text} explicitly
- Validate every entry, not just the first
- Filter or default malformed records before building the dialog
When it happens
Trigger: inputOptions: [{value: 1}, {text: 'No value'}]; entries built with label or name instead of text; a JSON source using {id, title} keys copied in verbatim; one malformed record in an otherwise good server response.
Common situations: Mapping an API payload to inputOptions but forgetting to rename fields (id→value, name→text); sparse data where some records lack a label; hand-written option arrays with inconsistent shapes.
Related errors
- invalid prompt type
- prompt with select requires options
- Please supply an object of options
- Please specify a message
- button with key {key} must be an object
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/3aa25ac6ed8facec.
Report an issue: GitHub.