grafana/k6 · error

open() failed, unable to verify if %q exists; reason: %w

Error message

open() failed, unable to verify if %q exists; reason: %w

What it means

Thrown by the experimental fs module's open() in the init context. After resolving the path against the init CWD, k6 calls fsext.Exists to verify it; if that check itself errors (not 'file missing' - a missing file produces a NotFoundError 'no such file or directory'), the error is wrapped as 'open() failed, unable to verify if %q exists' (internal/js/modules/k6/experimental/fs/module.go:125). The failure is in the underlying filesystem's Stat, and the resolved path is included in the message.

Source

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

	path = strings.TrimPrefix(path, "file://")

	// We resolve the path relative to the entrypoint script, as opposed to
	// the current working directory (the k6 command is called from).
	//
	// This is done on purpose, although it diverges in some respect with
	// 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
	}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Check the exact path printed in the message - spelling and case - relative to the script's directory
  2. Verify read permission on the file and every parent directory (chmod/chcon as needed)
  3. If running from an archive, rebuild it from the original script tree instead of editing it by hand
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const f = open(path);
} catch (e) {
  if (/unable to verify if .* exists/.test(e.message)) {
    throw new Error(`stat failed for ${path}: check permissions and archive integrity`);
  }
  throw e;
}

Prevention

When it happens

Trigger: fs.open(path) where Stat on the resolved path fails: permission denied on the file or a parent directory, a corrupted entry inside a k6 archive, or an fsext backend error.

Common situations: Restrictive permissions in hardened containers/CI runners; manually unpacked and repacked k6 archives; case-sensitivity mistakes that surface as stat failures on case-sensitive filesystems.

Related errors


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