grafana/k6 · error
parsing file descriptor: %w
Error message
parsing file descriptor: %w
What it means
Thrown while parsing the files argument of ElementHandle.setInputFiles. k6 exports each JavaScript file descriptor object into the Go File struct via rt.ExportTo, and the export fails because the object's shape does not match. The expected descriptor is { name: string, mimeType: string, buffer: string } (File struct in element_handle_options.go:92). Fields with mismatched types (e.g. a buffer that is not a string) make the export fail.
Source
Thrown at internal/js/modules/k6/browser/common/element_handle_options.go:233
// NewElementHandleSetInputFilesOptions creates a new ElementHandleSetInputFilesOption.
func NewElementHandleSetInputFilesOptions(defaultTimeout time.Duration) *ElementHandleSetInputFilesOptions {
return &ElementHandleSetInputFilesOptions{
ElementHandleBaseOptions: *NewElementHandleBaseOptions(defaultTimeout),
}
}
// 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() {View on GitHub (pinned to 93accf6570)
Solutions
- Make each descriptor exactly { name: string, mimeType: string, buffer: string }
- Encode binary payloads into a string (e.g. base64 via k6/encoding) before putting them in buffer
- Log each descriptor before calling setInputFiles to find the malformed one
- For arrays, verify every element is a plain object with string-valued fields
Example fix
// before
await el.setInputFiles([{ name: 'f.bin', mimeType: 'application/octet-stream', buffer: 12345 }]);
// after
import encoding from 'k6/encoding';
const b64 = encoding.b64encode('\x00\x01\x02', 'std');
await el.setInputFiles([{ name: 'f.bin', mimeType: 'application/octet-stream', buffer: b64 }]); Defensive patterns
Strategy: validation
Validate before calling
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');
}
const files = [{ name: 'a.txt', mimeType: 'text/plain', buffer: 'hello' }];
if (!files.every(isFileDescriptor)) throw new Error('malformed file descriptor');
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 (/parsing file descriptor/.test(e.message)) {
// normalize every descriptor to {name, mimeType, buffer} strings and retry
} else throw e;
} Prevention
- Build descriptors from one helper so the shape stays consistent
- Encode binary payloads as strings before passing them
- Remember k6 wants {name, mimeType, buffer}, not Playwright Buffer objects
- Validate array elements before the call, not after the failure
When it happens
Trigger: setInputFiles([{ name: 'a.txt', mimeType: 'text/plain', buffer: 123 }]) with a non-string buffer; descriptor objects containing nested objects, arrays, or numbers where strings are expected; one malformed element inside an otherwise valid files array.
Common situations: Porting Playwright scripts: Playwright accepts { name, mimeType, buffer: Buffer } while this k6 browser version expects buffer as a string; building descriptors dynamically without validating field types; passing binary data unwrapped.
Related errors
- parsing setInputFiles parameter: %w
- invalid parameter type : %s
- predicate function is not callable
- "handler" argument cannot be nil
- clip area is either empty or outside the viewport
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/67f4e79f8e777ab0.
Report an issue: GitHub.