{"record":{"id":"bc539d526e1c645e","repo":"grafana/k6","slug":"first-argument-expected-to-be-a-fs-file-instance","errorCode":null,"errorMessage":"first argument expected to be a fs.File instance, got %T instead","messagePattern":"first argument expected to be a fs\\.File instance, got %T instead","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/experimental/csv/module.go","lineNumber":104,"sourceCode":"\t// options holds the parser's as provided by the user.\n\toptions options\n\n\t// vu is the VU instance that owns this module instance.\n\tvu modules.VU\n}\n\n// parseSharedArrayNamePrefix is the prefix used for the shared array names created by the Parse function.\nconst parseSharedArrayNamePrefix = \"csv.parse.\"\n\n// Parse parses the provided CSV file, and returns a promise that resolves to a shared array\n// containing the parsed data.\nfunc (mi *ModuleInstance) Parse(file sobek.Value, options sobek.Value) (*sobek.Promise, error) {\n\trt := mi.vu.Runtime()\n\n\t// 1. Make sure the Sobek object is a fs.File (Sobek operation)\n\tvar fileObj fs.File\n\tif err := mi.vu.Runtime().ExportTo(file, &fileObj); err != nil {\n\t\treturn nil, fmt.Errorf(\"first argument expected to be a fs.File instance, got %T instead\", file)\n\t}\n\n\tparserOptions := newDefaultParserOptions()\n\tif options != nil {\n\t\tvar err error\n\t\tparserOptions, err = newParserOptionsFrom(options.ToObject(rt))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to interpret the provided Parser options; reason: %w\", err)\n\t\t}\n\t}\n\n\tr, err := NewReaderFrom(fileObj.ReadSeekStater, parserOptions)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create a new parser; reason: %w\", err)\n\t}\n\n\tunderlyingSharedArrayName, err := buildSharedArrayName(fileObj, parserOptions)\n\tif err != nil {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/experimental/csv/module.go#L86-L122","documentation":"Returned by csv.Parse when ExportTo cannot coerce the first Sobek argument into an fs.File — a type guard whose '%T' names the actual runtime type received. The API requires an opened file object (from k6/experimental/fs open()); passing a string path, a plain object, or any other value fires this immediately, before any parsing or option handling occurs.","triggerScenarios":"Thrown at internal/js/modules/k6/experimental/csv/module.go:104 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Open the file first: const f = await open('data.csv') and pass the result to csv.parse","Do not pass a file path string or raw object as the first argument","Ensure you are not passing the result of a different module's open()"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}