{"record":{"id":"6ada643723ce1f39","repo":"grafana/k6","slug":"options-expected-array-got-t","errorCode":null,"errorMessage":"options: expected array, got %T","messagePattern":"options: expected array, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/mapping.go","lineNumber":63,"sourceCode":"\t\treturn nil, fmt.Errorf(\"parsing click options: %w\", err)\n\t}\n\treturn copts, nil\n}\n\nfunc ConvertSelectOptionValues(rt *sobek.Runtime, values sobek.Value) ([]any, error) {\n\tif k6common.IsNullish(values) {\n\t\treturn nil, nil\n\t}\n\n\tvar (\n\t\topts []any\n\t\tt    = values.Export()\n\t)\n\tswitch values.ExportType().Kind() {\n\tcase reflect.Slice:\n\t\tvar sl []any\n\t\tif err := rt.ExportTo(values, &sl); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"options: expected array, got %T\", values)\n\t\t}\n\n\t\tfor _, item := range sl {\n\t\t\tswitch item := item.(type) {\n\t\t\tcase string:\n\t\t\t\t// Strings will match values or labels\n\t\t\t\tvalOpt := common.SelectOption{Value: new(string)}\n\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)","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/mapping.go#L45-L81","documentation":"Defensive branch inside ConvertSelectOptionValues: the values argument exported as a Go slice kind, but sobek could not export it into []any. With plain JavaScript arrays this practically never happens; it guards exotic runtime values (custom array-like objects produced by native bindings or corrupted sobek values). When it does fire, selectOption rejects with 'parsing select option values: options: expected array, got <type>'.","triggerScenarios":"Passing a selectOption values argument that is a slice-typed sobek value not produced from a plain JS array — e.g. a value marshaled from Go code or a native object whose array conversion fails during ExportTo.","commonSituations":"Extensions or xk6 modules feeding non-standard array objects into the browser module; edge cases after runtime upgrades that change sobek export behavior.","solutions":["Pass a plain JavaScript array literal: selectOption(['red', { label: 'Green' }])","Convert exotic values with Array.from(values) before calling selectOption","Rebuild the value from raw data (strings and plain objects) rather than passing foreign objects","Report persistent cases to k6 browser module maintainers with a minimal reproducer"],"exampleFix":"// before\nawait page.locator('select').selectOption(exoticArrayLike);\n\n// after\nawait page.locator('select').selectOption(Array.from(exoticArrayLike));","handlingStrategy":"type-guard","validationCode":"function toPlainArray(values) {\n  if (values === null || values === undefined) return values;\n  if (Array.isArray(values)) return values; // plain JS array always exports cleanly\n  if (typeof values === 'string' || typeof values === 'object') return Array.from(values);\n  throw new TypeError(`selectOption values must be a string, array, or object, got ${typeof values}`);\n}","typeGuard":"function isPlainSelectArray(v) {\n  return Array.isArray(v);\n}","tryCatchPattern":"try {\n  await locator.selectOption(values, opts);\n} catch (e) {\n  if (/expected array/.test(String(e.message))) {\n    // rebuild as a literal array and retry once with validated items\n    const plain = (Array.isArray(values) ? values : Array.from(values ?? []))\n      .map((x) => (typeof x === 'number' ? { index: x } : x));\n    await locator.selectOption(plain, opts);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Pass array literals built in JS, never foreign/native array objects","Normalize with Array.from() when values come from other modules","Keep a single conversion helper for selectOption inputs"],"tags":["k6","browser","selectoption","type-validation","defensive"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}