{"record":{"id":"0bfb9f2b8b578803","repo":"grafana/k6","slug":"open-can-t-be-used-with-directories-path-q","errorCode":null,"errorMessage":"open() can't be used with directories, path: %q","messagePattern":"open\\(\\) can't be used with directories, path: %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/initcontext.go","lineNumber":53,"sourceCode":"}\n\nfunc readFile(fileSystem fsext.Fs, filename string) (data []byte, err error) {\n\tdefer func() {\n\t\tif errors.Is(err, fsext.ErrPathNeverRequestedBefore) {\n\t\t\t// loading different files per VU is not supported, so all files should are going\n\t\t\t// to be used inside the scenario should be opened during the init step (without any conditions)\n\t\t\terr = fmt.Errorf(\n\t\t\t\t\"open() can't be used with files that weren't previously opened during initialization (__VU==0), path: %q\",\n\t\t\t\tfilename,\n\t\t\t)\n\t\t}\n\t}()\n\n\t// Workaround for https://github.com/spf13/fsext/issues/201\n\tif isDir, err := fsext.IsDir(fileSystem, filename); err != nil {\n\t\treturn nil, err\n\t} else if isDir {\n\t\treturn nil, fmt.Errorf(\"open() can't be used with directories, path: %q\", filename)\n\t}\n\n\treturn fsext.ReadFile(fileSystem, filename)\n}\n\n// allowOnlyOpenedFiles enables seen only files\nfunc allowOnlyOpenedFiles(fs fsext.Fs) {\n\talreadyOpenedFS, ok := fs.(fsext.OnlyCachedEnabler)\n\tif !ok {\n\t\treturn\n\t}\n\n\talreadyOpenedFS.AllowOnlyCached()\n}\n\nfunc generateSourceMapLoader(logger logrus.FieldLogger, filesystems map[string]fsext.Fs,\n) func(path string) ([]byte, error) {\n\treturn func(path string) ([]byte, error) {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/initcontext.go#L35-L71","documentation":"Validation in readFile (initcontext.go): the path passed to open() resolves to a directory on the (fs) filesystem, not a readable file. k6 cannot return directory contents to the script.","triggerScenarios":"Thrown at internal/js/initcontext.go:53 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Point open() at a file, not a directory","Check for typos or missing filename in the path","If loading multiple files, open each file individually"],"exampleFix":null,"handlingStrategy":"validation","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"}