{"record":{"id":"04f010d0bc7f37cf","repo":"grafana/k6","slug":"options-v-expected-string-got-t","errorCode":null,"errorMessage":"options[%v]: expected string, got %T","messagePattern":"options\\[(.+?)\\]: expected string, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/mapping.go","lineNumber":140,"sourceCode":"\t\t*labelOpt.Label = t.(string) //nolint:forcetypeassert\n\t\topts = append(opts, &valOpt, &labelOpt)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"options: unsupported type %T\", values)\n\t}\n\n\treturn opts, nil\n}\n\nfunc extractSelectOptionFromMap(v map[string]any) (*common.SelectOption, error) {\n\topt := &common.SelectOption{}\n\tfor k, raw := range v {\n\t\tswitch k {\n\t\tcase \"value\":\n\t\t\topt.Value = new(string)\n\n\t\t\tv, ok := raw.(string)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"options[%v]: expected string, got %T\", k, raw)\n\t\t\t}\n\n\t\t\t*opt.Value = v\n\t\tcase \"label\":\n\t\t\topt.Label = new(string)\n\n\t\t\tv, ok := raw.(string)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"options[%v]: expected string, got %T\", k, raw)\n\t\t\t}\n\t\t\t*opt.Label = v\n\t\tcase \"index\":\n\t\t\topt.Index = new(int64)\n\n\t\t\tswitch raw := raw.(type) {\n\t\t\tcase int:\n\t\t\t\t*opt.Index = int64(raw)\n\t\t\tcase int64:","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/mapping.go#L122-L158","documentation":"Thrown by extractSelectOptionFromMap when a selectOption descriptor object has a value or label key that is not a string. The value and label fields must be strings (index must be an integer); anything else rejects with 'options[<key>]: expected string, got <type>' (e.g. options[value]: expected string, got float64), wrapped by the mapping as 'parsing select option values: ...'.","triggerScenarios":"selectOption({ value: 2 }) — numeric value instead of string; selectOption({ label: null }); selectOption([{ value: ['a'] }]) — array-valued descriptor field; only index may be numeric.","commonSituations":"JSON fixtures where option values are numbers; sloppy destructuring leaving undefined/null in descriptors; mixing index and value conventions in one descriptor with wrong types.","solutions":["Stringify value and label: selectOption({ value: String(id) })","Use { index: n } (number) for positional selection, not { value: n }","Drop null/undefined keys from descriptors instead of passing them","Validate descriptor objects against { value?: string, label?: string, index?: number } before the call"],"exampleFix":"// before\nawait page.locator('select').selectOption({ value: 42 });\n\n// after\nawait page.locator('select').selectOption({ value: '42' }); // or { index: 42 }","handlingStrategy":"type-guard","validationCode":"function normalizeDescriptor(d) {\n  const o = {};\n  if (d.value !== undefined && d.value !== null) {\n    if (typeof d.value !== 'string') throw new TypeError(`descriptor value must be a string, got ${typeof d.value}`);\n    o.value = d.value;\n  }\n  if (d.label !== undefined && d.label !== null) {\n    if (typeof d.label !== 'string') throw new TypeError(`descriptor label must be a string, got ${typeof d.label}`);\n    o.label = d.label;\n  }\n  if (d.index !== undefined) o.index = Number(d.index);\n  return o;\n}","typeGuard":"function isSelectDescriptor(v) {\n  if (typeof v !== 'object' || v === null || Array.isArray(v)) return false;\n  return (v.value === undefined || typeof v.value === 'string') &&\n         (v.label === undefined || typeof v.label === 'string') &&\n         (v.index === undefined || typeof v.index === 'number');\n}","tryCatchPattern":"try {\n  await locator.selectOption(values, opts);\n} catch (e) {\n  if (/options\\[.*\\]: expected string/.test(String(e.message))) {\n    throw new Error(`Descriptor value/label must be strings; use { index: n } for numbers: ${e.message}`);\n  }\n  throw e;\n}","preventionTips":["Stringify value and label fields coming from JSON or APIs","Reserve numbers for the index key only","Drop undefined/null keys from descriptors instead of passing them through"],"tags":["k6","browser","selectoption","type-validation","descriptor"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}