grafana/k6 · error
failed to read the content of file %s: %w
Error message
failed to read the content of file %s: %w
What it means
The experimental fs module's cache opened the underlying file successfully but io.ReadAll failed while reading its content (internal/js/modules/k6/experimental/fs/cache.go:104). This is an I/O-level read failure after a successful open - the file exists and opened, but its bytes could not be fully read. Distinct from a missing file, which fails earlier at the Exists check with a NotFoundError.
Source
Thrown at internal/js/modules/k6/experimental/fs/cache.go:104
return data, nil
}
// TODO: re-evaluate opening from the FS this once #1079 is resolved.
f, err := fromFs.Open(filename)
if err != nil {
return nil, err
}
defer func() {
cerr := f.Close()
if cerr != nil {
err = fmt.Errorf("failed to close file %s: %w", filename, cerr)
}
}()
data, err = io.ReadAll(f)
if err != nil {
return nil, fmt.Errorf("failed to read the content of file %s: %w", filename, err)
}
fr.openedFiles.Store(filename, data)
return data, nil
}
View on GitHub (pinned to 93accf6570)
Solutions
- Ensure data files are not modified while k6 reads them (use write-to-temp-then-rename on the producer side)
- Check file permissions and disk/volume health
- Copy the file next to the script and re-run to rule out remote-storage issues
Defensive patterns
Strategy: try-catch
Try / catch
try {
const file = open('./data.bin');
} catch (e) {
if (/failed to read the content of file/.test(e.message)) {
throw new Error(`data file unreadable: ${e.message}; verify it is not being rewritten during startup`);
}
throw e;
} Prevention
- Freeze data files before the run (write-then-rename on the producer side)
- Keep fixtures next to the script on local disk
- Checksum large fixtures in CI to catch truncated copies
When it happens
Trigger: fs.open(path) where the file is truncated or replaced between the existence check and the read, or where the underlying afero/fsext layer returns a read error (permissions changed mid-run, disk errors, flaky remote volume).
Common situations: External processes rewriting data files while the test starts; containers with unreliable mounted volumes; files on network storage that stat fine but read intermittently.
Related errors
- failed to close file %s: %w
- open() failed, unable to verify if %q exists; reason: %w
- open() failed, unable to verify if %q is a directory; reason
- persisting screenshot: %w
- the 'header' option cannot be enabled when 'fromLine' is set
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/05f2b11d7dee1ff0.
Report an issue: GitHub.