{"record":{"id":"1d05b7e8a804da27","repo":"grafana/k6","slug":"options-v-expected-int-got-t","errorCode":null,"errorMessage":"options[%v]: expected int, got %T","messagePattern":"options\\[(.+?)\\]: expected int, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/mapping.go","lineNumber":169,"sourceCode":"\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:\n\t\t\t\t*opt.Index = raw\n\t\t\tdefault:\n\t\t\t\treturn nil, fmt.Errorf(\"options[%v]: expected int, got %T\", k, raw)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn opt, nil\n}\n","sourceCodeStart":151,"sourceCodeEnd":176,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/mapping.go#L151-L176","documentation":"Thrown by extractSelectOptionFromMap (browser/mapping.go:161) while parsing a selectOption descriptor: the 'index' key was present but its value is neither int nor int64. Position-based selection requires { index: <integer> }; strings and floats fall into the default branch and are rejected with the key name in the message.","triggerScenarios":"page.selectOption('#sel', { index: '2' }) (string from JSON or user input) or { index: 2.5 } / { index: 2.0 } when the value arrives as float64 — Sobek only exports whole numbers written as integer literals as int64, so floats parsed from JSON can fail even when they look whole.","commonSituations":"Index values read from JSON/CSV files (parsed as string or float); indices computed by arithmetic that produced a float; Playwright porting where index came through a serialization boundary.","solutions":["Pass an integer literal: { index: 2 }.","Coerce at the boundary: { index: Number(data.idx) } and check Number.isInteger first.","Truncate computed floats: { index: Math.trunc(pos) } when the fractional part is noise.","Prefer value/label matching over index when the dataset is string-typed."],"exampleFix":"// before\nawait page.selectOption('#sel', { index: data.position }); // \"2\"\n\n// after\nconst idx = Number(data.position);\nif (!Number.isInteger(idx)) throw new Error(`bad index: ${data.position}`);\nawait page.selectOption('#sel', { index: idx });","handlingStrategy":"type-guard","validationCode":"const opt = { ...raw };\nif ('index' in opt) {\n  const n = Number(opt.index);\n  if (!Number.isInteger(n)) throw new Error(`index must be an integer, got ${opt.index}`);\n  opt.index = n;\n}\nawait page.selectOption('#sel', opt);","typeGuard":"function hasIntegerIndex(o) {\n  return !('index' in o) || (typeof o.index === 'number' && Number.isInteger(o.index));\n}","tryCatchPattern":"try { await page.selectOption('#sel', opt); } catch (e) { if (/options\\[index\\]: expected int/.test(e.message)) { await page.selectOption('#sel', { ...opt, index: parseInt(opt.index, 10) }); } else throw e; }","preventionTips":["Always pass index as an integer, never a string or float.","parseInt/Number-convert indices read from files at load time.","Prefer value/label matching when your dataset is string-typed."],"tags":["k6","browser","select-option","type-validation","index-key"],"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"}