{"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":125,"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":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/mapping.go#L107-L143","documentation":"Thrown by ConvertSelectOptionValues when the selectOption values argument's exported kind matches none of the accepted cases: slice (array), map (plain object), *common.ElementHandle (an <option> element handle), or string. Numbers, booleans, functions, undefined-carrying slots, and any other kind reject with 'options: unsupported type <type>', wrapped by the mapping as 'parsing select option values: ...'.","triggerScenarios":"selectOption(2) — raw numeric index; selectOption(true); selectOption(() => {}) — function value; selectOption(Symbol()) or other unsupported kinds.","commonSituations":"Passing option indices as bare numbers (very common when porting from frameworks that accept numeric indexes); dynamically computed values whose type is not pinned down; forgetting that null/undefined is the only 'empty' value allowed.","solutions":["Use a descriptor for numeric selection: selectOption({ index: 2 })","Use a string for value/label matching: selectOption('red')","Pass null or undefined to express 'no selection', never false/0","Type-check dynamic values before the call and normalize them to string or descriptor"],"exampleFix":"// before\nawait page.locator('select.qty').selectOption(3);\n\n// after\nawait page.locator('select.qty').selectOption({ index: 3 });","handlingStrategy":"type-guard","validationCode":"function assertSelectValuesKind(values) {\n  if (values === null || values === undefined) return; // allowed: no selection\n  const t = typeof values;\n  if (t === 'string' || t === 'object') return; // string, array, plain object, ElementHandle\n  throw new TypeError(`selectOption values of type ${t} are not supported; use a string, {index:n}, or null`);\n}","typeGuard":"function isSelectOptionValues(v) {\n  if (v === null || v === undefined || typeof v === 'string') return true;\n  if (typeof v !== 'object') return false; // numbers, booleans, functions rejected\n  if (Array.isArray(v)) return v.every((it) => typeof it === 'string' || (typeof it === 'object' && it !== null));\n  return true; // plain object descriptor or ElementHandle-like\n}","tryCatchPattern":"try {\n  await locator.selectOption(values, opts);\n} catch (e) {\n  if (/unsupported type/.test(String(e.message))) {\n    throw new Error(`selectOption got an unsupported value (${typeof values}); wrap numbers as {index: n}`);\n  }\n  throw e;\n}","preventionTips":["Never pass bare numbers or booleans as values","Use { index: n } for positional selection and strings for value/label matching","Type-check dynamic values before the call"],"tags":["k6","browser","selectoption","type-validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}