grafana/k6 · error
copying data to file
Error message
copying data to file: %w
What it means
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.
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
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/storage/file_persister.go:45 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/86df3fd0ef631983.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/storage/file_persister.go:45
dir := filepath.Dir(cp)
if err = os.MkdirAll(dir, 0o755); err != nil { //nolint:forbidigo,gosec
return fmt.Errorf("creating a local directory %q: %w", dir, err)
}
f, err := os.OpenFile(cp, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600) //nolint:forbidigo
if err != nil {
return fmt.Errorf("creating a local file %q: %w", cp, err)
}
defer func() {
if cerr := f.Close(); cerr != nil && err == nil {
err = fmt.Errorf("closing the local file %q: %w", cp, cerr)
}
}()
bf := bufio.NewWriter(f)
if _, err := io.Copy(bf, data); err != nil {
return fmt.Errorf("copying data to file: %w", err)
}
if err := bf.Flush(); err != nil {
return fmt.Errorf("flushing data to disk: %w", err)
}
return nil
}
// RemoteFilePersister is to be used when files created by the browser module need
// to be uploaded to a remote location. This uses a presignedURLRequestURL to
// retrieve one presigned URL. The presigned url is used to upload the file
// to the remote location.
type RemoteFilePersister struct {
presignedURLRequestURL string
headers map[string]string
basePath string
View on GitHub (pinned to 8d06114777)