{"record":{"id":"79a7d4cf5a2e5f91","repo":"grafana/k6","slug":"parsing-setinputfiles-parameter-w","errorCode":null,"errorMessage":"parsing setInputFiles parameter: %w","messagePattern":"parsing setInputFiles parameter: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/element_handle_mapping.go","lineNumber":237,"sourceCode":"\t\t\t}), nil\n\t\t},\n\t\t\"setChecked\": func(checked bool, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts := common.NewElementHandleSetCheckedOptions(eh.DefaultTimeout())\n\t\t\tif err := popts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing setChecked options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, eh.SetChecked(checked, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"setInputFiles\": func(files sobek.Value, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts := common.NewElementHandleSetInputFilesOptions(eh.DefaultTimeout())\n\t\t\tif err := popts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing setInputFiles options: %w\", err)\n\t\t\t}\n\t\t\tvar pfiles common.Files\n\t\t\tif err := pfiles.Parse(vu.Context(), files); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing setInputFiles parameter: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, eh.SetInputFiles(&pfiles, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"tap\": func(opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts := common.NewElementHandleTapOptions(eh.Timeout())\n\t\t\tif err := popts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing element tap options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, eh.Tap(popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"textContent\": func() *sobek.Promise {\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\ts, ok, err := eh.TextContent()\n\t\t\t\tif err != nil {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/element_handle_mapping.go#L219-L255","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass descriptor objects: { name: 'report.pdf', mimeType: 'application/pdf', buffer: encoding.b64encode(bytes) }","Load local files with open('report.pdf', 'b') and base64-encode the bytes with k6/encoding before the call","For arrays, ensure every element is a descriptor object, never a path string or number","Validate descriptors (string name/mimeType/buffer) before calling, and catch synchronously with try/catch"],"exampleFix":"// before\nimport { open } from 'k6/experimental/streams';\nawait el.setInputFiles('/tmp/report.pdf');\n\n// after\nimport encoding from 'k6/encoding';\nconst bytes = open('/tmp/report.pdf', 'b');\nawait el.setInputFiles({\n  name: 'report.pdf',\n  mimeType: 'application/pdf',\n  buffer: encoding.b64encode(bytes),\n});","handlingStrategy":"validation","validationCode":"import encoding from 'k6/encoding';\nfunction toDescriptor(f) {\n  if (typeof f !== 'object' || f === null || Array.isArray(f)) {\n    throw new Error('setInputFiles(): files must be { name, mimeType, buffer } or an array of them (path strings are not supported)');\n  }\n  if (typeof f.name !== 'string' || typeof f.mimeType !== 'string' || typeof f.buffer !== 'string') {\n    throw new Error('setInputFiles(): descriptor requires string name, mimeType, and base64 buffer');\n  }\n  return f;\n}\n// const bytes = open('/tmp/report.pdf', 'b');\n// const files = [{ name: 'report.pdf', mimeType: 'application/pdf', buffer: encoding.b64encode(bytes) }];\nconst files2 = (Array.isArray(files) ? files : [files]).map(toDescriptor);","typeGuard":"function isFileDescriptor(f) {\n  return typeof f === 'object' && f !== null && !Array.isArray(f) &&\n    typeof f.name === 'string' && typeof f.mimeType === 'string' &&\n    typeof f.buffer === 'string';\n}\nfunction isFilesArg(v) {\n  if (v == null) return true;\n  return isFileDescriptor(v) || (Array.isArray(v) && v.every(isFileDescriptor));\n}","tryCatchPattern":"try {\n  await el.setInputFiles(files, opts);\n} catch (e) {\n  if (/parsing setInputFiles parameter|invalid parameter type|parsing file descriptor/.test(String(e.message))) {\n    console.log(`fix files argument (must be descriptors, not paths): ${e.message}`);\n  } else throw e;\n}","preventionTips":["k6 element setInputFiles takes no file paths: build { name, mimeType, buffer } descriptors","Load files with open(path, 'b') and base64-encode via k6/encoding before the browser session","Every array element must be a descriptor object; mixed arrays with strings are rejected"],"tags":["k6","browser","element-handle","set-input-files","file-upload"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}