grafana/k6 · error

caching data read from -: %w

Error message

caching data read from -: %w

What it means

Raised in ReadSource when the script '-' (stdin) was read successfully but writing the read data to the in-memory filesystem cache failed. It means the test source came from stdin but could not be cached for subsequent reads. The at-fault input is the stdin content read from '-'.

Source

Thrown at internal/loader/readsource.go:30

	"go.k6.io/k6/v2/lib/fsext"
)

// ReadSource Reads a source file from any supported destination.
func ReadSource(
	logger logrus.FieldLogger, src, pwd string, filesystems map[string]fsext.Fs, stdin io.Reader,
) (*SourceData, error) {
	// 'ToSlash' is here as URL only use '/' as separators, but on Windows paths use '\'
	pwdURL := &url.URL{Scheme: "file", Path: filepath.ToSlash(filepath.Clean(pwd)) + "/"}
	if src == "-" {
		data, err := io.ReadAll(stdin)
		if err != nil {
			return nil, err
		}
		// TODO: don't do it in this way ...
		//nolint:forcetypeassert
		err = fsext.WriteFile(filesystems["file"].(fsext.CacheLayerGetter).GetCachingFs(), "/-", data, 0o644)
		if err != nil {
			return nil, fmt.Errorf("caching data read from -: %w", err)
		}
		return &SourceData{URL: &url.URL{Path: "/-", Scheme: "file"}, Data: data, PWD: pwdURL}, err
	}
	var srcLocalPath string
	if filepath.IsAbs(src) {
		srcLocalPath = src
	} else {
		srcLocalPath = filepath.Join(pwd, src)
	}
	// All paths should start with a / in all fses. This is mostly for windows where it will start
	// with a volume name : C:\something.js
	srcLocalPath = filepath.Clean(fsext.FilePathSeparator + srcLocalPath)
	if ok, _ := fsext.Exists(filesystems["file"], srcLocalPath); ok {
		// there is file on the local disk ... lets use it :)
		return Load(logger, filesystems, &url.URL{Scheme: "file", Path: filepath.ToSlash(srcLocalPath)}, src)
	}

	srcURL, err := Resolve(pwdURL, filepath.ToSlash(src))

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Check that stdin was provided correctly (e.g. k6 run - < script.js)
  2. Retry if the write failure was transient (disk/memory)
  3. Use a regular file path instead of stdin as the test source
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at internal/loader/readsource.go:30 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/a5249115df351872. Report an issue: GitHub.