{"record":{"id":"86df3fd0ef631983","repo":"grafana/k6","slug":"copying-data-to-file-w","errorCode":null,"errorMessage":"copying data to file: %w","messagePattern":"copying data to file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/storage/file_persister.go","lineNumber":45,"sourceCode":"\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\n\tif err := bf.Flush(); err != nil {\n\t\treturn fmt.Errorf(\"flushing data to disk: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// RemoteFilePersister is to be used when files created by the browser module need\n// to be uploaded to a remote location. This uses a presignedURLRequestURL to\n// retrieve one presigned URL. The presigned url is used to upload the file\n// to the remote location.\ntype RemoteFilePersister struct {\n\tpresignedURLRequestURL string\n\theaders                map[string]string\n\tbasePath               string\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/storage/file_persister.go#L27-L63","documentation":"Raised in LocalFilePersister.Persist when io.Copy from the source data reader into the buffered writer fails while streaming artifact bytes to the local file. The failure originates from either the reader (upstream produce error) or the writer (disk full, I/O error). The file has already been created and truncated, so a partial file may remain on disk.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/storage/file_persister.go:45 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check available disk space on the artifact destination","Verify the source data reader (e.g. CDP screenshot stream) is not failing mid-transfer","Retry the persist; be aware a partial file may need manual cleanup","Look at the wrapped error to distinguish reader-side from writer-side failure"],"exampleFix":null,"handlingStrategy":"retry","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"}