grafana/k6 · error

parsing setInputFiles parameter: %w

Error message

parsing setInputFiles parameter: %w

What it means

Thrown synchronously by ElementHandle.setInputFiles() when the files argument cannot be parsed. common.Files.Parse (element_handle_options.go) only accepts a file descriptor object or an array of them: each item must export to a Go map, so Files.addFile reports 'invalid parameter type : <kind>' for strings/numbers/booleans, and 'parsing file descriptor: <cause>' when an object does not match the { name, mimeType, buffer } struct. Unlike Playwright, k6's element-handle setInputFiles does not accept local file path strings.

Source

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

			}), nil
		},
		"setChecked": func(checked bool, opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewElementHandleSetCheckedOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); 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 := common.NewElementHandleSetInputFilesOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); 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 := common.NewElementHandleTapOptions(eh.Timeout())
			if err := popts.Parse(vu.Context(), opts); 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
		},
		"textContent": func() *sobek.Promise {
			return promise(vu, func() (any, error) {
				s, ok, err := eh.TextContent()
				if err != nil {

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass descriptor objects: { name: 'report.pdf', mimeType: 'application/pdf', buffer: encoding.b64encode(bytes) }
  2. Load local files with open('report.pdf', 'b') and base64-encode the bytes with k6/encoding before the call
  3. For arrays, ensure every element is a descriptor object, never a path string or number
  4. Validate descriptors (string name/mimeType/buffer) before calling, and catch synchronously with try/catch

Example fix

// before
import { open } from 'k6/experimental/streams';
await el.setInputFiles('/tmp/report.pdf');

// after
import encoding from 'k6/encoding';
const bytes = open('/tmp/report.pdf', 'b');
await el.setInputFiles({
  name: 'report.pdf',
  mimeType: 'application/pdf',
  buffer: encoding.b64encode(bytes),
});
Defensive patterns

Strategy: validation

Validate before calling

import encoding from 'k6/encoding';
function toDescriptor(f) {
  if (typeof f !== 'object' || f === null || Array.isArray(f)) {
    throw new Error('setInputFiles(): files must be { name, mimeType, buffer } or an array of them (path strings are not supported)');
  }
  if (typeof f.name !== 'string' || typeof f.mimeType !== 'string' || typeof f.buffer !== 'string') {
    throw new Error('setInputFiles(): descriptor requires string name, mimeType, and base64 buffer');
  }
  return f;
}
// const bytes = open('/tmp/report.pdf', 'b');
// const files = [{ name: 'report.pdf', mimeType: 'application/pdf', buffer: encoding.b64encode(bytes) }];
const files2 = (Array.isArray(files) ? files : [files]).map(toDescriptor);

Type guard

function isFileDescriptor(f) {
  return typeof f === 'object' && f !== null && !Array.isArray(f) &&
    typeof f.name === 'string' && typeof f.mimeType === 'string' &&
    typeof f.buffer === 'string';
}
function isFilesArg(v) {
  if (v == null) return true;
  return isFileDescriptor(v) || (Array.isArray(v) && v.every(isFileDescriptor));
}

Try / catch

try {
  await el.setInputFiles(files, opts);
} catch (e) {
  if (/parsing setInputFiles parameter|invalid parameter type|parsing file descriptor/.test(String(e.message))) {
    console.log(`fix files argument (must be descriptors, not paths): ${e.message}`);
  } else throw e;
}

Prevention

When it happens

Trigger: el.setInputFiles('/tmp/report.pdf') (path string; kind string is rejected), el.setInputFiles(5), el.setInputFiles(['a.txt', { name: 'b', mimeType: 'text/plain', buffer: b64 }]) (string item inside array rejected), or an object with non-string buffer. buffer must be a base64-encoded string.

Common situations: Porting Playwright scripts that pass file paths directly; assuming k6's open() path semantics apply here. Developers must read the file in the script with open(path, 'b') and base64-encode it (e.g. via k6/encoding) before passing the descriptor.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/79a7d4cf5a2e5f91. Report an issue: GitHub.