grafana/k6 · error

parsing setInputFiles options

Error message

parsing setInputFiles options: %w

What it means

Thrown when ElementHandle.setInputFiles cannot parse its second (options) argument. ElementHandleSetInputFilesOptions embeds only ElementHandleBaseOptions, whose Parse coerces force/noWaitAfter/timeout via sobek coercion and never type-fails, and unknown keys are ignored. This wrap is defensive: in current code the wrapped Parse has no realistic error path, so seeing it usually indicates an internal/runtime problem rather than a bad options key.

Solutions

  1. Pass the options argument as a plain object, null, or undefined: setInputFiles(files, {timeout: 5000}) or setInputFiles(files)
  2. If it persists with a plain object, check the actual error being wrapped (%w) — it points inside the runtime, not at your options keys
  3. Report as a k6 browser module bug if reproducible with an ordinary object

Example fix

// before
await handle.setInputFiles(file, '5000');
// after
await handle.setInputFiles(file, { timeout: 5000 });
Defensive patterns

Strategy: try-catch

Validate before calling

if (opts != null && typeof opts !== 'object') {
  throw new Error(`setInputFiles options must be an object, got ${typeof opts}`);
}
await handle.setInputFiles(files, opts);

Type guard

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

Try / catch

try {
  await handle.setInputFiles(files, opts);
} catch (e) {
  if (String(e).includes('parsing setInputFiles options')) {
    // wrap is defensive; log the inner error and fall back to no options
    await handle.setInputFiles(files);
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling handle.setInputFiles(files, opts) where opts is a primitive (number, string, symbol) that cannot be coerced to an object, or a runtime-level export failure inside ElementHandleBaseOptions.Parse. Passing a normal object, null, or undefined never triggers it.

Common situations: Almost never seen in the wild; the options keys force/noWaitAfter/timeout are coercion-tolerant and typos are silently ignored. If it appears, suspect a modified/older k6 build or an options value that is not a plain object.

Related errors


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-09-14). Data as JSON: /api/errors/fe61d6f259f0b2c7. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/browser/element_handle_mapping.go:240

				return nil, fmt.Errorf("parsing selectText options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.SelectText(popts) //nolint:wrapcheck
			}), nil
		},
		"setChecked": func(checked bool, opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseElementHandleSetCheckedOptions(rt, opts, eh.DefaultTimeout())
			if err != nil {
				return nil, fmt.Errorf("parsing setChecked options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.SetChecked(checked, popts) //nolint:wrapcheck
			}), nil
		},
		"setInputFiles": func(files sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseElementHandleSetInputFilesOptions(rt, opts, eh.DefaultTimeout())
			if err != nil {
				return nil, fmt.Errorf("parsing setInputFiles options: %w", err)
			}
			var pfiles common.Files
			if err := pfiles.Parse(vu.Context(), files); err != nil {
				return nil, fmt.Errorf("parsing setInputFiles parameter: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.SetInputFiles(&pfiles, popts) //nolint:wrapcheck
			}), nil
		},
		"tap": func(opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseElementHandleTapOptions(rt, opts, eh.Timeout())
			if err != nil {
				return nil, fmt.Errorf("parsing element tap options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.Tap(popts) //nolint:wrapcheck
			}), nil
		},

View on GitHub (pinned to 3fcf5388d7)