{"record":{"id":"c70c1b7059000f55","repo":"grafana/k6","slug":"options-expected-object-got-t","errorCode":null,"errorMessage":"options: expected object, got %T","messagePattern":"options: expected object, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/mapping.go","lineNumber":97,"sourceCode":"\t\t\t\t*valOpt.Value = item\n\t\t\t\tlabelOpt := common.SelectOption{Label: new(string)}\n\t\t\t\t*labelOpt.Label = item\n\t\t\t\topts = append(opts, &valOpt, &labelOpt)\n\t\t\tcase map[string]any:\n\t\t\t\topt, err := extractSelectOptionFromMap(item)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\n\t\t\t\topts = append(opts, opt)\n\t\t\tdefault:\n\t\t\t\treturn nil, fmt.Errorf(\"options: expected string or object, got %T\", item)\n\t\t\t}\n\t\t}\n\tcase reflect.Map:\n\t\tvar raw map[string]any\n\t\tif err := rt.ExportTo(values, &raw); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"options: expected object, got %T\", values)\n\t\t}\n\n\t\topt, err := extractSelectOptionFromMap(raw)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\topts = append(opts, opt)\n\tcase reflect.TypeFor[*common.ElementHandle]().Kind():\n\t\topts = append(opts, t.(*common.ElementHandle)) //nolint:forcetypeassert\n\tcase reflect.TypeFor[sobek.Object]().Kind():\n\t\tobj := values.ToObject(rt)\n\t\topt := common.SelectOption{}\n\t\tfor _, k := range obj.Keys() {\n\t\t\tswitch k {\n\t\t\tcase \"value\":\n\t\t\t\topt.Value = new(string)\n\t\t\t\t*opt.Value = obj.Get(k).String()","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/mapping.go#L79-L115","documentation":"Thrown by ConvertSelectOptionValues when the selectOption argument classifies as an object/map (reflect.Map) but Sobek cannot export it to map[string]any (browser/mapping.go:89). The single-object form selectOption({value:'x'}) is valid, so this error means the map itself could not be read — typically a non-plain-object map-like value with non-string keys or an object from outside plain JS.","triggerScenarios":"Passing a Map instance with non-string keys, or an object produced by a Go binding whose export type is a map with non-string key types, to page.selectOption('#sel', obj). Plain JS object literals with string keys never trigger this.","commonSituations":"Using new Map([['value','x']]) instead of an object literal; receiving option descriptors from exported Go functions; almost never occurs with hand-written objects in a test script.","solutions":["Use a plain object literal: page.selectOption('#sel', { value: 'blue' }).","Convert Map instances first: Object.fromEntries(myMap).","Keep keys to 'value', 'label', 'index' with correct value types (string, string, int).","Verify with typeof obj === 'object' && !Array.isArray(obj) before the call."],"exampleFix":"// before\nawait page.selectOption('#sel', new Map([['value', 'blue']]));\n\n// after\nawait page.selectOption('#sel', { value: 'blue' });","handlingStrategy":"type-guard","validationCode":"const obj = raw instanceof Map ? Object.fromEntries(raw) : raw;\nawait page.selectOption('#sel', typeof obj === 'object' && obj !== null ? obj : { value: String(raw) });","typeGuard":"function isPlainSelectObject(v) {\n  return v != null && typeof v === 'object' && !Array.isArray(v) && !(v instanceof Map) && !(v instanceof Set);\n}","tryCatchPattern":"try { await page.selectOption('#sel', obj); } catch (e) { if (/options: expected object/.test(e.message)) { await page.selectOption('#sel', Object.fromEntries(obj)); } else throw e; }","preventionTips":["Use object literals, not Map instances, for single selectOption descriptors.","Keep descriptor keys limited to value, label, index.","Normalize objects received from bindings with Object.fromEntries when needed."],"tags":["k6","browser","select-option","type-validation","object"],"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"}