{"record":{"id":"fc225a29c8309c85","repo":"grafana/k6","slug":"parsing-select-options-values-w-fc225a","errorCode":null,"errorMessage":"parsing select options values: %w","messagePattern":"parsing select options values: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/frame_mapping.go","lineNumber":338,"sourceCode":"\t\t},\n\t\t\"press\": func(selector, key string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parseFramePressOptions(rt, opts, f.Timeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parse press options of selector %q on key %q: %w\", selector, key, err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, f.Press(selector, key, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"selectOption\": func(selector string, values sobek.Value, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parseFrameSelectOptionOptions(rt, opts, f.Timeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing select option options: %w\", err)\n\t\t\t}\n\n\t\t\tconvValues, err := ConvertSelectOptionValues(rt, values)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing select options values: %w\", err)\n\t\t\t}\n\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn f.SelectOption(selector, convValues, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"setChecked\": func(selector string, checked bool, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parseFrameCheckOptions(rt, opts, f.Timeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing frame set check options: %w\", err)\n\t\t\t}\n\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, f.SetChecked(selector, checked, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"setContent\": func(html string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parseFrameSetContentOptions(rt, opts, f.Page().NavigationTimeout())","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/frame_mapping.go#L320-L356","documentation":"Thrown when the `values` argument of `frame.selectOption(selector, values, opts)` cannot be converted by ConvertSelectOptionValues. Accepted shapes: a single string, a single object {value?, label?, index?}, an ElementHandle, or an array mixing strings and such objects. Rejections: array items that are numbers/booleans/null ('options: expected string or object, got %T'), value/label not strings ('options[value]: expected string, got %T'), index not an integer ('options[index]: expected int, got %T'), or a top-level unsupported type like a number ('options: unsupported type').","triggerScenarios":"`frame.selectOption('#s', [1, 2])` (numeric indexes must be objects: [{index: 1}]); `frame.selectOption('#s', [{ value: 42 }])`; `frame.selectOption('#s', true)`; float index `{ index: 1.5 }`.","commonSituations":"Porting from Playwright where numbers in arrays are also rejected — but developers commonly build option arrays dynamically from JSON data where numbers sneak in; passing booleans or null from loose data parsing.","solutions":["Wrap numeric selections in objects: [{ index: 1 }] instead of [1]","Ensure value/label are strings and index is an integer","Validate/normalize the values array before the call when it comes from external data"],"exampleFix":"// before\nawait frame.selectOption('#qty', [2, { value: 'xl' }]);\n\n// after\nawait frame.selectOption('#qty', [{ index: 2 }, { value: 'xl' }]);","handlingStrategy":"type-guard","validationCode":"function normalizeSelectValues(values) {\n  const arr = Array.isArray(values) ? values : [values];\n  return arr.map(v => {\n    if (typeof v === 'string') return v;\n    if (v && typeof v === 'object' && !Array.isArray(v)) {\n      if (v.value !== undefined && typeof v.value !== 'string') throw new Error('value must be a string');\n      if (v.label !== undefined && typeof v.label !== 'string') throw new Error('label must be a string');\n      if (v.index !== undefined && !Number.isInteger(v.index)) throw new Error('index must be an integer');\n      return v;\n    }\n    if (typeof v === 'number') return { index: v };\n    throw new Error(`unsupported select option value: ${JSON.stringify(v)}`);\n  });\n}","typeGuard":"function isSelectOptionValue(v) {\n  if (typeof v === 'string') return true;\n  if (v == null || typeof v !== 'object' || Array.isArray(v)) return false;\n  const { value, label, index } = v;\n  return (value === undefined || typeof value === 'string') &&\n         (label === undefined || typeof label === 'string') &&\n         (index === undefined || Number.isInteger(index));\n}","tryCatchPattern":"try {\n  await frame.selectOption(sel, values, opts);\n} catch (e) {\n  if (String(e).includes('parsing select options values')) {\n    console.error('values must be string | {value?,label?,index?} | ElementHandle, or an array of these');\n    throw e;\n  }\n  throw e;\n}","preventionTips":["Wrap bare numbers as { index: n } — plain numbers in the array are rejected","value and label must be strings; index must be an integer (no floats)","Sanitize data-driven option lists before the call"],"tags":["k6","browser","frame","select-option","values","type-conversion"],"backgroundTag":"invalid-argument-value","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}