grafana/k6 · error

open() failed, unable to verify if %q is a directory; reason

Error message

open() failed, unable to verify if %q is a directory; reason: %w

What it means

The experimental fs module's open() runs two probes before returning a file: Exists, then fsext.IsDir (opening a directory is rejected separately). If the IsDir probe itself errors, it is wrapped as 'open() failed, unable to verify if %q is a directory' (internal/js/modules/k6/experimental/fs/module.go:131). The file was confirmed to exist; the failure is the directory-check Stat call on the filesystem backend.

Source

Thrown at internal/js/modules/k6/experimental/fs/module.go:131

	// how files are handled in different k6 contexts, so that we cater to
	// and intuitive user experience.
	//
	// See #2781 and #2674.
	path = fsext.Abs(initEnv.CWD.Path, path)

	fs, ok := initEnv.FileSystems["file"]
	if !ok {
		return nil, errors.New("open() failed; reason: unable to access the file system")
	}

	if exists, err := fsext.Exists(fs, path); err != nil {
		return nil, fmt.Errorf("open() failed, unable to verify if %q exists; reason: %w", path, err)
	} else if !exists {
		return nil, newFsError(NotFoundError, fmt.Sprintf("no such file or directory %q", path))
	}

	if isDir, err := fsext.IsDir(fs, path); err != nil {
		return nil, fmt.Errorf("open() failed, unable to verify if %q is a directory; reason: %w", path, err)
	} else if isDir {
		return nil, newFsError(
			InvalidResourceError,
			fmt.Sprintf("cannot open %q: opening a directory is not supported", path),
		)
	}

	data, err := mi.cache.open(path, fs)
	if err != nil {
		return nil, err
	}

	file := &File{
		Path: path,
		ReadSeekStater: &file{
			path: path,
			data: data,
		},

View on GitHub (pinned to 93accf6570)

Solutions

  1. Re-check permissions on the file and parent directories
  2. Re-run - a transient failure between two consecutive stat calls is the most likely cause
  3. If reproducible from an archive, rebuild the archive from source files
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const f = open(path);
} catch (e) {
  if (/unable to verify if .* is a directory/.test(e.message)) {
    // existence already passed; retry once, then check permissions/mount health
    return open(path);
  }
  throw e;
}

Prevention

When it happens

Trigger: fs.open(path) on a path whose Stat for the IsDir check fails - permission revoked between the two checks, corrupted archive entries with valid name but broken metadata, or an fsext/afero backend error.

Common situations: Same class as the existence-check failure: hardened CI environments with restrictive permissions, hand-edited k6 archives, and unusual mounts; the existence check passed moments earlier, so it is usually transient or metadata-specific.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/5430be752ed34804. Report an issue: GitHub.