grafana/k6 · error

creating a local directory

Error message

creating a local directory %q: %w

What it means

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.

Solutions

  1. Check that the process has write permission on the parent directory
  2. Verify no regular file occupies a needed directory component in the path
  3. Use an absolute, writable base directory for browser artifact storage
  4. Ensure the disk is not full or the filesystem read-only
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/storage/file_persister.go:29 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/58e3daeaaff82912. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/storage/file_persister.go:29

	"mime/multipart"
	"net/http"
	"os"
	"path/filepath"
	"strings"
	"time"
)

// LocalFilePersister will persist files to the local disk.
type LocalFilePersister struct{}

// Persist will write the contents of data to the local disk on the specified path.
// TODO: we should not write to disk here but put it on some queue for async disk writes.
func (l *LocalFilePersister) Persist(_ context.Context, path string, data io.Reader) (err error) {
	cp := filepath.Clean(path)

	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)
	}

View on GitHub (pinned to 8d06114777)