{"record":{"id":"b9f5b731bf03f739","repo":"redis/node-redis","slug":"failed-to-read-filepath-from-container-stder","errorCode":null,"errorMessage":"Failed to read ${filePath} from container: ${stderr}","messagePattern":"Failed to read (.+?) from container: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/test-utils/lib/dockers.ts","lineNumber":264,"sourceCode":"\n/**\n * Reads a file from a Docker container directly into memory\n * @param dockerId - The Docker container ID\n * @param filePath - Path to the file inside the container\n * @returns Buffer containing the file contents\n */\nasync function readFileFromContainer(\n  dockerId: string,\n  filePath: string,\n): Promise<Buffer> {\n  const { stdout, stderr } = await execAsync(\"docker\", [\n    \"exec\",\n    dockerId,\n    \"cat\",\n    filePath,\n  ]);\n  if (stderr) {\n    throw new Error(`Failed to read ${filePath} from container: ${stderr}`);\n  }\n  return Buffer.from(stdout);\n}\n\n/**\n * Loads TLS certificates from a running Docker container into memory\n * @param dockerId - The Docker container ID\n * @param certName - The certificate name (used for client cert/key naming)\n * @returns TlsCertificates object with ca, cert, and key buffers\n */\nasync function loadTlsCertificates(\n  dockerId: string,\n  certName: string,\n): Promise<TlsCertificates> {\n  const [ca, cert, key] = await Promise.all([\n    readFileFromContainer(dockerId, `${DEFAULT_TLS_PATH}/ca.crt`),\n    readFileFromContainer(dockerId, `${DEFAULT_TLS_PATH}/${certName}.crt`),\n    readFileFromContainer(dockerId, `${DEFAULT_TLS_PATH}/${certName}.key`),","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/redis/node-redis/blob/90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58/packages/test-utils/lib/dockers.ts#L246-L282","documentation":"readFileFromContainer runs `docker exec <id> cat <filePath>` and throws when stderr is non-empty. It is used internally by loadTlsCertificates to extract ca.crt, <cert>.crt, and <cert>.key from a running Redis container into memory. Any stderr from the exec aborts the read.","triggerScenarios":"The TLS cert file does not yet exist at the expected path (/redis/work/tls/<file>); the container exited before the cat; the path is wrong for the image's TLS layout; permission denied reading the key file.","commonSituations":"Calling loadTlsCertificates before the container's cert-generation step finished; image version that stores certs under a different directory; container crashed during startup.","solutions":["Exec into the container to inspect the path: docker exec <id> ls -l /redis/work/tls","Ensure waitForTlsCertificates completed successfully before calling loadTlsCertificates","Check the container is still running: docker ps --filter id=<id>"],"exampleFix":"# before — file missing, cat writes to stderr\n# Error: Failed to read /redis/work/tls/client.crt from container: cat: ...: No such file\n\n# after — verify the file exists first\ndocker exec <id> ls -l /redis/work/tls/\n# wait for cert generation, then retry","handlingStrategy":"validation","validationCode":"async function fileExistsInContainer(dockerId: string, filePath: string): Promise<boolean> {\n  try {\n    await execAsync('docker', ['exec', dockerId, 'test', '-f', filePath]);\n    return true;\n  } catch {\n    return false;\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const buf = await readFileFromContainer(dockerId, filePath);\n} catch (e) {\n  if (e instanceof Error && /Failed to read/.test(e.message)) {\n  }\n  throw e;\n}","preventionTips":["Always call waitForTlsCertificates before loadTlsCertificates so files exist","Verify the cert path layout matches the image version before reading","Log the container id alongside the failure so a developer can docker exec into it"],"tags":["docker","tls","certificates","test-utils","filesystem"],"backgroundTag":null,"analyzedSha":"90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58","analyzedAt":"2026-08-11T15:37:21.243Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}