{"record":{"id":"a5249115df351872","repo":"grafana/k6","slug":"caching-data-read-from-w","errorCode":null,"errorMessage":"caching data read from -: %w","messagePattern":"caching data read from -: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/loader/readsource.go","lineNumber":30,"sourceCode":"\t\"go.k6.io/k6/v2/lib/fsext\"\n)\n\n// ReadSource Reads a source file from any supported destination.\nfunc ReadSource(\n\tlogger logrus.FieldLogger, src, pwd string, filesystems map[string]fsext.Fs, stdin io.Reader,\n) (*SourceData, error) {\n\t// 'ToSlash' is here as URL only use '/' as separators, but on Windows paths use '\\'\n\tpwdURL := &url.URL{Scheme: \"file\", Path: filepath.ToSlash(filepath.Clean(pwd)) + \"/\"}\n\tif src == \"-\" {\n\t\tdata, err := io.ReadAll(stdin)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\t// TODO: don't do it in this way ...\n\t\t//nolint:forcetypeassert\n\t\terr = fsext.WriteFile(filesystems[\"file\"].(fsext.CacheLayerGetter).GetCachingFs(), \"/-\", data, 0o644)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"caching data read from -: %w\", err)\n\t\t}\n\t\treturn &SourceData{URL: &url.URL{Path: \"/-\", Scheme: \"file\"}, Data: data, PWD: pwdURL}, err\n\t}\n\tvar srcLocalPath string\n\tif filepath.IsAbs(src) {\n\t\tsrcLocalPath = src\n\t} else {\n\t\tsrcLocalPath = filepath.Join(pwd, src)\n\t}\n\t// All paths should start with a / in all fses. This is mostly for windows where it will start\n\t// with a volume name : C:\\something.js\n\tsrcLocalPath = filepath.Clean(fsext.FilePathSeparator + srcLocalPath)\n\tif ok, _ := fsext.Exists(filesystems[\"file\"], srcLocalPath); ok {\n\t\t// there is file on the local disk ... lets use it :)\n\t\treturn Load(logger, filesystems, &url.URL{Scheme: \"file\", Path: filepath.ToSlash(srcLocalPath)}, src)\n\t}\n\n\tsrcURL, err := Resolve(pwdURL, filepath.ToSlash(src))","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/loader/readsource.go#L12-L48","documentation":"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 '-'.","triggerScenarios":"Thrown at internal/loader/readsource.go:30 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check that stdin was provided correctly (e.g. k6 run - < script.js)","Retry if the write failure was transient (disk/memory)","Use a regular file path instead of stdin as the test source"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}