grafana/k6 · error

options: unsupported type %T

Error message

options: unsupported type %T

What it means

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.

Solutions

  1. Wrap the value in the correct shape: string 'blue', object { index: 2 }, or array ['blue'].
  2. Guard the call: only invoke selectOption when the value is a string, array, object, or ElementHandle.
  3. Default missing data explicitly: const v = data.choice ?? 'none'.
  4. To select by position, always use { index: n } — never the bare number.

Example fix

// before
await page.selectOption('#sel', 2);

// after
await page.selectOption('#sel', { index: 2 });
Defensive patterns

Strategy: type-guard

Validate before calling

function toSelectValues(v) {
  if (typeof v === 'string' || Array.isArray(v)) return v;
  if (v != null && typeof v === 'object') return [v];
  throw new Error(`selectOption values must be string/array/object, got ${typeof v}`);
}
await page.selectOption('#sel', toSelectValues(cfg.choice));

Type guard

function isSelectOptionValues(v) {
  return typeof v === 'string' || Array.isArray(v) || (v != null && typeof v === 'object');
}

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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


AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18). Data as JSON: /api/errors/b76dab0b88797d59. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/browser/mapping.go:133

				*opt.Value = obj.Get(k).String()
			case "label":
				opt.Label = new(string)
				*opt.Label = obj.Get(k).String()
			case "index":
				opt.Index = new(int64)
				*opt.Index = obj.Get(k).ToInteger()
			}
		}
		opts = append(opts, &opt)
	case reflect.String:
		// Strings will match values or labels
		valOpt := common.SelectOption{Value: new(string)}
		*valOpt.Value = t.(string) //nolint:forcetypeassert
		labelOpt := common.SelectOption{Label: new(string)}
		*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

View on GitHub (pinned to 8d06114777)