{"record":{"id":"b76dab0b88797d59","repo":"grafana/k6","slug":"options-unsupported-type-t","errorCode":null,"errorMessage":"options: unsupported type %T","messagePattern":"options: unsupported type %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/mapping.go","lineNumber":133,"sourceCode":"\t\t\t\t*opt.Value = obj.Get(k).String()\n\t\t\tcase \"label\":\n\t\t\t\topt.Label = new(string)\n\t\t\t\t*opt.Label = obj.Get(k).String()\n\t\t\tcase \"index\":\n\t\t\t\topt.Index = new(int64)\n\t\t\t\t*opt.Index = obj.Get(k).ToInteger()\n\t\t\t}\n\t\t}\n\t\topts = append(opts, &opt)\n\tcase reflect.String:\n\t\t// Strings will match values or labels\n\t\tvalOpt := common.SelectOption{Value: new(string)}\n\t\t*valOpt.Value = t.(string) //nolint:forcetypeassert\n\t\tlabelOpt := common.SelectOption{Label: new(string)}\n\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","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/mapping.go#L115-L151","documentation":"Thrown by ConvertSelectOptionValues when the top-level selectOption argument has a type the converter does not handle at all (default branch, browser/mapping.go:125). Accepted top-level types are: string, array, plain object, ElementHandle, and Sobek object. Anything else — number, boolean, function, symbol — is rejected before any selection is attempted.","triggerScenarios":"page.selectOption('#sel', 42), selectOption('#sel', true), or selectOption('#sel', () => 'red'). Also passing a variable that is undefined-but-not-null in the checked sense, or a single option index as a bare number.","commonSituations":"Passing an index directly (selectOption(el, 2)) instead of { index: 2 }); variables that failed an earlier lookup and became undefined/NaN; data-driven scripts where the CSV/JSON field is empty and coerces to a non-string primitive.","solutions":["Wrap the value in the correct shape: string 'blue', object { index: 2 }, or array ['blue'].","Guard the call: only invoke selectOption when the value is a string, array, object, or ElementHandle.","Default missing data explicitly: const v = data.choice ?? 'none'.","To select by position, always use { index: n } — never the bare number."],"exampleFix":"// before\nawait page.selectOption('#sel', 2);\n\n// after\nawait page.selectOption('#sel', { index: 2 });","handlingStrategy":"type-guard","validationCode":"function toSelectValues(v) {\n  if (typeof v === 'string' || Array.isArray(v)) return v;\n  if (v != null && typeof v === 'object') return [v];\n  throw new Error(`selectOption values must be string/array/object, got ${typeof v}`);\n}\nawait page.selectOption('#sel', toSelectValues(cfg.choice));","typeGuard":"function isSelectOptionValues(v) {\n  return typeof v === 'string' || Array.isArray(v) || (v != null && typeof v === 'object');\n}","tryCatchPattern":"try { await page.selectOption('#sel', cfg.choice); } catch (e) { if (/options: unsupported type/.test(e.message)) { await page.selectOption('#sel', { index: Number(cfg.choice) }); } else throw e; }","preventionTips":["Never pass a bare number or boolean as selectOption values.","Select by position with { index: n }, never the raw integer.","Default missing data explicitly instead of letting undefined leak into the call."],"tags":["k6","browser","select-option","type-validation","unsupported-type"],"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"}