{"record":{"id":"05f2b11d7dee1ff0","repo":"grafana/k6","slug":"failed-to-read-the-content-of-file-s-w","errorCode":null,"errorMessage":"failed to read the content of file %s: %w","messagePattern":"failed to read the content of file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/experimental/fs/cache.go","lineNumber":104,"sourceCode":"\n\t\treturn data, nil\n\t}\n\n\t// TODO: re-evaluate opening from the FS this once #1079 is resolved.\n\tf, err := fromFs.Open(filename)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer func() {\n\t\tcerr := f.Close()\n\t\tif cerr != nil {\n\t\t\terr = fmt.Errorf(\"failed to close file %s: %w\", filename, cerr)\n\t\t}\n\t}()\n\n\tdata, err = io.ReadAll(f)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read the content of file %s: %w\", filename, err)\n\t}\n\n\tfr.openedFiles.Store(filename, data)\n\n\treturn data, nil\n}\n","sourceCodeStart":86,"sourceCodeEnd":111,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/experimental/fs/cache.go#L86-L111","documentation":"The experimental fs module's cache opened the underlying file successfully but io.ReadAll failed while reading its content (internal/js/modules/k6/experimental/fs/cache.go:104). This is an I/O-level read failure after a successful open - the file exists and opened, but its bytes could not be fully read. Distinct from a missing file, which fails earlier at the Exists check with a NotFoundError.","triggerScenarios":"fs.open(path) where the file is truncated or replaced between the existence check and the read, or where the underlying afero/fsext layer returns a read error (permissions changed mid-run, disk errors, flaky remote volume).","commonSituations":"External processes rewriting data files while the test starts; containers with unreliable mounted volumes; files on network storage that stat fine but read intermittently.","solutions":["Ensure data files are not modified while k6 reads them (use write-to-temp-then-rename on the producer side)","Check file permissions and disk/volume health","Copy the file next to the script and re-run to rule out remote-storage issues"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const file = open('./data.bin');\n} catch (e) {\n  if (/failed to read the content of file/.test(e.message)) {\n    throw new Error(`data file unreadable: ${e.message}; verify it is not being rewritten during startup`);\n  }\n  throw e;\n}","preventionTips":["Freeze data files before the run (write-then-rename on the producer side)","Keep fixtures next to the script on local disk","Checksum large fixtures in CI to catch truncated copies"],"tags":["fs","k6","io","experimental","read-failure"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}