{"record":{"id":"58e3daeaaff82912","repo":"grafana/k6","slug":"creating-a-local-directory-q-w","errorCode":null,"errorMessage":"creating a local directory %q: %w","messagePattern":"creating a local directory %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/storage/file_persister.go","lineNumber":29,"sourceCode":"\t\"mime/multipart\"\n\t\"net/http\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strings\"\n\t\"time\"\n)\n\n// LocalFilePersister will persist files to the local disk.\ntype LocalFilePersister struct{}\n\n// Persist will write the contents of data to the local disk on the specified path.\n// TODO: we should not write to disk here but put it on some queue for async disk writes.\nfunc (l *LocalFilePersister) Persist(_ context.Context, path string, data io.Reader) (err error) {\n\tcp := filepath.Clean(path)\n\n\tdir := filepath.Dir(cp)\n\tif err = os.MkdirAll(dir, 0o755); err != nil { //nolint:forbidigo,gosec\n\t\treturn fmt.Errorf(\"creating a local directory %q: %w\", dir, err)\n\t}\n\n\tf, err := os.OpenFile(cp, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600) //nolint:forbidigo\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating a local file %q: %w\", cp, err)\n\t}\n\tdefer func() {\n\t\tif cerr := f.Close(); cerr != nil && err == nil {\n\t\t\terr = fmt.Errorf(\"closing the local file %q: %w\", cp, cerr)\n\t\t}\n\t}()\n\n\tbf := bufio.NewWriter(f)\n\n\tif _, err := io.Copy(bf, data); err != nil {\n\t\treturn fmt.Errorf(\"copying data to file: %w\", err)\n\t}\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/storage/file_persister.go#L11-L47","documentation":"Raised in LocalFilePersister.Persist when os.MkdirAll fails to create the directory portion ('%q') of the cleaned target path before opening the file for writing. This is a filesystem-level failure: the path's parent directory cannot be created due to permission denial, a path component being a file, read-only filesystem, or invalid path characters. The input at fault is the destination path the browser module computed for the artifact being saved.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/storage/file_persister.go:29 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check that the process has write permission on the parent directory","Verify no regular file occupies a needed directory component in the path","Use an absolute, writable base directory for browser artifact storage","Ensure the disk is not full or the filesystem read-only"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}