grafana/k6 · error
invalid parameter type : %s
Error message
invalid parameter type : %s
What it means
Returned by Files.addFile when an entry of the files argument is not an object. The switch only accepts reflect.Map (a plain JS object used as a file descriptor); anything else — a string, number, or boolean — hits the default branch. Unlike Playwright, this k6 browser version does not accept file paths: setInputFiles takes descriptor objects ({ name, mimeType, buffer }) only. The %s is the Go reflect.Kind name such as 'string' or 'int64'.
Source
Thrown at internal/js/modules/k6/browser/common/element_handle_options.go:237
}
}
// addFile to the struct. Input value can only be a file descriptor object.
func (f *Files) addFile(ctx context.Context, file sobek.Value) error {
if common.IsNullish(file) {
return nil
}
rt := k6ext.Runtime(ctx)
fileType := file.ExportType()
switch fileType.Kind() {
case reflect.Map: // file descriptor object
var parsedFile File
if err := rt.ExportTo(file, &parsedFile); err != nil {
return fmt.Errorf("parsing file descriptor: %w", err)
}
f.Payload = append(f.Payload, &parsedFile)
default:
return fmt.Errorf("invalid parameter type : %s", fileType.Kind().String())
}
return nil
}
// Parse parses the Files struct from the given sobek.Value.
func (f *Files) Parse(ctx context.Context, files sobek.Value) error {
rt := k6ext.Runtime(ctx)
if common.IsNullish(files) {
return nil
}
optsType := files.ExportType()
switch optsType.Kind() {
case reflect.Slice: // array of filePaths or array of file descriptor objects
gopts := files.ToObject(rt)
for _, k := range gopts.Keys() {
err := f.addFile(ctx, gopts.Get(k))View on GitHub (pinned to 93accf6570)
Solutions
- Replace path strings with descriptor objects: { name: 'a.pdf', mimeType: 'application/pdf', buffer: '<contents as string>' }
- Read and encode file contents in the script (open() / k6/encoding) and pass the string in buffer
- Read the kind name in the message to identify the bad entry: 'string' means a path was passed
Example fix
// before
await el.setInputFiles(['/uploads/report.pdf']);
// after
await el.setInputFiles([{ name: 'report.pdf', mimeType: 'application/pdf', buffer: pdfContentString }]); Defensive patterns
Strategy: validation
Validate before calling
const files = ['/a.pdf', { name: 'b.pdf', mimeType: 'application/pdf', buffer: s }];
const ok = files.every(f => f && typeof f === 'object' && !Array.isArray(f));
if (!ok) throw new Error('setInputFiles requires descriptor objects, not paths');
await el.setInputFiles(files); Type guard
function isFileDescriptor(o) {
return !!o && typeof o === 'object' && !Array.isArray(o) &&
typeof o.name === 'string' && typeof o.mimeType === 'string' &&
(o.buffer === undefined || typeof o.buffer === 'string');
} Try / catch
try {
await el.setInputFiles(files);
} catch (e) {
if (/invalid parameter type/.test(e.message)) {
// convert string paths into {name, mimeType, buffer} descriptors and retry
} else throw e;
} Prevention
- Never pass filesystem paths to setInputFiles in this module version
- Centralize descriptor creation in a single helper
- Assert the input is an array of plain objects before calling
When it happens
Trigger: setInputFiles('/path/to/file.txt') or setInputFiles(['a.pdf', 'b.pdf']) — paths are strings, not objects; a number or boolean inside the files array; any non-plain-object entry reaching addFile.
Common situations: Copy-pasting Playwright tests that use local file paths; assuming k6 reads files from disk like Playwright does; mixing selector strings or numbers into the files argument.
Related errors
- parsing setInputFiles parameter: %w
- parsing file descriptor: %w
- parsing setInputFiles options: %w
- setting input files: %w
- parsing element handle click option modifiers: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/80dc82e4ecd08554.
Report an issue: GitHub.