grafana/k6 · error
options[ ]: expected string, got %T
Error message
options[%v]: expected string, got %T
What it means
Thrown by extractSelectOptionFromMap (browser/mapping.go:140) while parsing a selectOption descriptor object: the 'value' key was present but its value is not a string. k6 requires value-based selection descriptors to be { value: '<string>' }; the type assertion raw.(string) fails for any other Go export type and the offending key name is included in the message.
Solutions
- Quote the value: { value: '123' } or { value: String(optionValue) }.
- Coerce at the data boundary: options = rawOptions.map(o => ({ ...o, value: String(o.value) })).
- If the option genuinely has no value attribute, match by label ({ label: '...' }) or index ({ index: n }) instead.
- Add a runtime check that every descriptor's value field is typeof 'string'.
Example fix
// before
await page.selectOption('#sel', { value: data.userId }); // userId = 1001
// after
await page.selectOption('#sel', { value: String(data.userId) }); Defensive patterns
Strategy: type-guard
Validate before calling
const opt = { ...raw };
if ('value' in opt && typeof opt.value !== 'string') opt.value = String(opt.value);
await page.selectOption('#sel', opt); Type guard
function hasStringValue(o) {
return !('value' in o) || typeof o.value === 'string';
} Try / catch
try { await page.selectOption('#sel', opt); } catch (e) { if (/options\[value\]: expected string/.test(e.message)) { await page.selectOption('#sel', { ...opt, value: String(opt.value) }); } else throw e; } Prevention
- Quote value fields in JSON datasets used for selection.
- Coerce value to String where data is loaded, not at the call site.
- Type descriptors as { value?: string; label?: string; index?: number }.
When it happens
Trigger: page.selectOption('#sel', { value: 123 }), { value: true }, or { value: null }. Numeric option values read from JSON without string conversion are the classic case.
Common situations: Option values sourced from a JSON/CSV dataset where values are numbers; APIs that return option values as integers; shared option objects reused from URL query building where numbers are common.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- options: expected array, got %T
- options: expected object, got %T
- options: expected string or object, got %T
- options: unsupported type %T
- options[ ]: expected int, got %T
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/04f010d0bc7f37cf.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/browser/mapping.go:148
*labelOpt.Label = t.(string) //nolint:forcetypeassert
opts = append(opts, &valOpt, &labelOpt)
default:
return nil, fmt.Errorf("options: unsupported type %T", values)
}
return opts, nil
}
func extractSelectOptionFromMap(v map[string]any) (*common.SelectOption, error) {
opt := &common.SelectOption{}
for k, raw := range v {
switch k {
case "value":
opt.Value = new(string)
v, ok := raw.(string)
if !ok {
return nil, fmt.Errorf("options[%v]: expected string, got %T", k, raw)
}
*opt.Value = v
case "label":
opt.Label = new(string)
v, ok := raw.(string)
if !ok {
return nil, fmt.Errorf("options[%v]: expected string, got %T", k, raw)
}
*opt.Label = v
case "index":
opt.Index = new(int64)
switch raw := raw.(type) {
case int:
*opt.Index = int64(raw)
case int64:View on GitHub (pinned to 8d06114777)