{"record":{"id":"0c29eab21942719e","repo":"eyaltoledano/claude-task-master","slug":"input-file-prdpath-is-empty-or-could-not-be-rea","errorCode":null,"errorMessage":"Input file ${prdPath} is empty or could not be read.","messagePattern":"Input file (.+?) is empty or could not be read\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/parse-prd/parse-prd-helpers.js","lineNumber":35,"sourceCode":" * Estimate token count from text\n * @param {string} text - Text to estimate tokens for\n * @returns {number} Estimated token count\n */\nexport function estimateTokens(text) {\n\t// Common approximation: ~4 characters per token for English\n\treturn Math.ceil(text.length / 4);\n}\n\n/**\n * Read and validate PRD content\n * @param {string} prdPath - Path to PRD file\n * @returns {string} PRD content\n * @throws {Error} If file is empty or cannot be read\n */\nexport function readPrdContent(prdPath) {\n\tconst prdContent = fs.readFileSync(prdPath, 'utf8');\n\tif (!prdContent) {\n\t\tthrow new Error(`Input file ${prdPath} is empty or could not be read.`);\n\t}\n\treturn prdContent;\n}\n\n/**\n * Load existing tasks from file\n * @param {string} tasksPath - Path to tasks file\n * @param {string} targetTag - Target tag to load from\n * @returns {{tasks: Array, nextId: number}} Existing tasks and next ID\n */\nexport function loadExistingTasks(tasksPath, targetTag) {\n\tlet existingTasks = [];\n\tlet nextId = 1;\n\n\tif (!fs.existsSync(tasksPath)) {\n\t\treturn { existingTasks, nextId };\n\t}\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/parse-prd/parse-prd-helpers.js#L17-L53","documentation":"readPrdContent reads the PRD file synchronously with fs.readFileSync(prdPath, 'utf8') and throws a plain Error when the result is falsy (empty string). This catches zero-byte files and certain read failures surfaced as empty content, ensuring parse-prd never proceeds with no input. Note fs.readFileSync throws its own ENOENT/EISDIR errors for missing files, so this specific message usually means the file exists but is empty.","triggerScenarios":"Passing a PRD path to a zero-byte file; a path to a directory or unreadable file in environments where readFileSync returns empty; shell redirection creating an empty file before parse (e.g. `> prd.txt` then parsing); variable expansion producing an empty path that resolves oddly.","commonSituations":"CI pipelines where the PRD artifact failed to upload/download; users creating the PRD file but forgetting to save content; typo'd env var (PRD_PATH=) combined with fallback path resolution; Windows/Unix path issues pointing at the wrong file.","solutions":["Check the file is non-empty: `wc -c prd.txt` or fs.statSync size > 0, then add content and retry.","Verify the resolved path is the intended PRD (log prdPath before calling).","If the file doesn't exist you'll get ENOENT instead — create the PRD file first.","Fix CI artifact steps so the PRD is generated before parse-prd runs.","Guard the call: validate file existence and size before invoking readPrdContent."],"exampleFix":"// before\nconst content = readPrdContent(prdPath); // throws on empty file\n// after\nimport fs from 'fs';\nif (!fs.existsSync(prdPath) || fs.statSync(prdPath).size === 0) {\n  throw new Error(`PRD at ${prdPath} is missing or empty; add content first.`);\n}\nconst content = readPrdContent(prdPath);","handlingStrategy":"validation","validationCode":"import fs from 'fs';\nif (!fs.existsSync(prdPath) || fs.statSync(prdPath).size === 0) {\n  throw new Error(`PRD file ${prdPath} is missing or empty.`);\n}","typeGuard":"function isReadableNonEmptyFile(path) {\n  try {\n    const st = fs.statSync(path);\n    return st.isFile() && st.size > 0;\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  const content = readPrdContent(prdPath);\n} catch (e) {\n  if (e.message.includes('is empty or could not be read')) {\n    console.error(`PRD at ${prdPath} is empty; provide content before parsing.`);\n  } else throw e;\n}","preventionTips":["Verify PRD file size > 0 before invoking parse-prd.","Fix CI artifact generation so the PRD exists with content before parsing.","Log the resolved prdPath to catch wrong-path/env-var mistakes.","Avoid creating PRD files via redirection placeholders that stay empty."],"tags":["file-io","parse-prd","empty-file"],"backgroundTag":"empty-input-file","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}