{"record":{"id":"80dc82e4ecd08554","repo":"grafana/k6","slug":"invalid-parameter-type-s","errorCode":null,"errorMessage":"invalid parameter type : %s","messagePattern":"invalid parameter type : (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle_options.go","lineNumber":237,"sourceCode":"\t}\n}\n\n// addFile to the struct. Input value can only be a file descriptor object.\nfunc (f *Files) addFile(ctx context.Context, file sobek.Value) error {\n\tif common.IsNullish(file) {\n\t\treturn nil\n\t}\n\trt := k6ext.Runtime(ctx)\n\tfileType := file.ExportType()\n\tswitch fileType.Kind() {\n\tcase reflect.Map: // file descriptor object\n\t\tvar parsedFile File\n\t\tif err := rt.ExportTo(file, &parsedFile); err != nil {\n\t\t\treturn fmt.Errorf(\"parsing file descriptor: %w\", err)\n\t\t}\n\t\tf.Payload = append(f.Payload, &parsedFile)\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid parameter type : %s\", fileType.Kind().String())\n\t}\n\n\treturn nil\n}\n\n// Parse parses the Files struct from the given sobek.Value.\nfunc (f *Files) Parse(ctx context.Context, files sobek.Value) error {\n\trt := k6ext.Runtime(ctx)\n\tif common.IsNullish(files) {\n\t\treturn nil\n\t}\n\n\toptsType := files.ExportType()\n\tswitch optsType.Kind() {\n\tcase reflect.Slice: // array of filePaths or array of file descriptor objects\n\t\tgopts := files.ToObject(rt)\n\t\tfor _, k := range gopts.Keys() {\n\t\t\terr := f.addFile(ctx, gopts.Get(k))","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle_options.go#L219-L255","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait el.setInputFiles(['/uploads/report.pdf']);\n\n// after\nawait el.setInputFiles([{ name: 'report.pdf', mimeType: 'application/pdf', buffer: pdfContentString }]);","handlingStrategy":"validation","validationCode":"const files = ['/a.pdf', { name: 'b.pdf', mimeType: 'application/pdf', buffer: s }];\nconst ok = files.every(f => f && typeof f === 'object' && !Array.isArray(f));\nif (!ok) throw new Error('setInputFiles requires descriptor objects, not paths');\nawait el.setInputFiles(files);","typeGuard":"function isFileDescriptor(o) {\n  return !!o && typeof o === 'object' && !Array.isArray(o) &&\n    typeof o.name === 'string' && typeof o.mimeType === 'string' &&\n    (o.buffer === undefined || typeof o.buffer === 'string');\n}","tryCatchPattern":"try {\n  await el.setInputFiles(files);\n} catch (e) {\n  if (/invalid parameter type/.test(e.message)) {\n    // convert string paths into {name, mimeType, buffer} descriptors and retry\n  } else throw e;\n}","preventionTips":["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"],"tags":["browser","file-upload","set-input-files","type-mismatch"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}