{"record":{"id":"3aa25ac6ed8facec","repo":"dianping/cat","slug":"given-options-in-wrong-format","errorCode":null,"errorMessage":"given options in wrong format","messagePattern":"given options in wrong format","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js","lineNumber":475,"sourceCode":"      case \"password\":\n        input.val(options.value);\n        break;\n\n      case \"select\":\n        var groups = {};\n        inputOptions = options.inputOptions || [];\n\n        if (!inputOptions.length) {\n          throw new Error(\"prompt with select requires options\");\n        }\n\n        each(inputOptions, function(_, option) {\n\n          // assume the element to attach to is the input...\n          var elem = input;\n\n          if (option.value === undefined || option.text === undefined) {\n            throw new Error(\"given options in wrong format\");\n          }\n\n\n          // ... but override that element if this option sits in a group\n\n          if (option.group) {\n            // initialise group if necessary\n            if (!groups[option.group]) {\n              groups[option.group] = $(\"<optgroup/>\").attr(\"label\", option.group);\n            }\n\n            elem = groups[option.group];\n          }\n\n          elem.append(\"<option value='\" + option.value + \"'>\" + option.text + \"</option>\");\n        });\n\n        each(groups, function(_, group) {","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js#L457-L493","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ninputOptions: response.users // [{id: 3, name: 'Ann'}, ...] -> throws\n\n// after\ninputOptions: response.users.map(function (u) {\n  return { value: u.id, text: u.name };\n})","handlingStrategy":"validation","validationCode":"function toInputOptions(rows) {\n  return rows.filter(function (r) { return r && r.id !== undefined && r.name !== undefined; })\n             .map(function (r) { return { value: r.id, text: r.name }; });\n}\nvar opts = toInputOptions(rows);\nif (opts.length) bootbox.prompt({ /* ... */ inputOptions: opts, callback: cb });","typeGuard":"function isWellFormedInputOption(o) {\n  return o !== null && typeof o === 'object' &&\n    o.value !== undefined && o.text !== undefined;\n}","tryCatchPattern":null,"preventionTips":["Map API records to {value, text} explicitly","Validate every entry, not just the first","Filter or default malformed records before building the dialog"],"tags":["bootbox","prompt","select","data-mapping","validation"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}