grafana/k6 · error
could not open '%s': %w
Error message
could not open '%s': %w
What it means
When the end-of-test summary is exported to files (handleSummary returning a map of paths to data, or --summary-export), k6 opens each path with O_WRONLY|O_CREAT|O_TRUNC via getWriter (only 'stdout' and 'stderr' are special-cased). If the file cannot be created or opened, the error is wrapped as "could not open '<path>'" and consolidated with other summary failures under 'Could not save some summary information:'.
Source
Thrown at internal/cmd/run.go:594
}
func handleSummaryResult(fs fsext.Fs, stdOut, stdErr io.Writer, result map[string]io.Reader) error {
var errs []error
getWriter := func(path string) (io.Writer, error) {
switch path {
case "stdout":
return stdOut, nil
case "stderr":
return stdErr, nil
default:
return fs.OpenFile(path, syscall.O_WRONLY|syscall.O_CREAT|syscall.O_TRUNC, 0o666)
}
}
for path, value := range result {
if writer, err := getWriter(path); err != nil {
errs = append(errs, fmt.Errorf("could not open '%s': %w", path, err))
} else if n, err := io.Copy(writer, value); err != nil {
errs = append(errs, fmt.Errorf("error saving summary to '%s' after %d bytes: %w", path, n, err))
}
}
return consolidateErrorMessage(errs, "Could not save some summary information:")
}
View on GitHub (pinned to 93accf6570)
Solutions
- Create the parent directory before the run: mkdir -p out/reports
- Use the special keys 'stdout' or 'stderr' in handleSummary when no file output is needed
- Verify the target directory exists and is writable by the k6 process user
- Treat every non-stdout/stderr key of handleSummary's return map as a file path that must be creatable, and validate them all
Example fix
// before
export function handleSummary(data) {
return { 'reports/summary.json': JSON.stringify(data) };
}
// after
export function handleSummary(data) {
return { stdout: textSummary(data), 'reports/summary.json': JSON.stringify(data) };
}
// plus in the shell: mkdir -p reports before k6 run Defensive patterns
Strategy: validation
Validate before calling
# Pre-create and verify every summary target directory
mkdir -p reports out
[ -w reports ] || { echo 'reports/ is not writable' >&2; exit 2; }
k6 run --summary-export=reports/summary.json script.js Prevention
- Use only 'stdout'/'stderr' or pre-created directories in handleSummary return maps
- Create summary directories in the CI job setup step
- Avoid absolute paths owned by other users (/var, /run)
- Validate all file paths once in a shared config before the run
When it happens
Trigger: handleSummary returns { 'out/reports/summary.json': JSON.stringify(data) } where out/reports/ does not exist; --summary-export points into a directory the k6 process cannot write; a directory component of the path is actually a regular file.
Common situations: CI containers writing summaries into directories never created in the image; paths on read-only mounts; typos in summary paths; switching summary output from stdout to a file without creating the folder.
Related errors
- error saving summary to '%s' after %d bytes: %w
- serialising archive: %w
- error writing error message to stderr: %w
- persisting screenshot: %w
- open() failed; reason: unable to access the file system
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/6b3414b9abfd9ca4.
Report an issue: GitHub.