{"record":{"id":"1c2e744ac1955a1a","repo":"itwanger/toBeBetterJavaer","slug":"path-not-found-target","errorCode":null,"errorMessage":"Path not found: ${target}","messagePattern":"Path not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/convert-mdnice-images-to-cdn.js","lineNumber":176,"sourceCode":"function validateOssConfig(config) {\n  const required = [\n    \"PAICODING_OSS_AK\",\n    \"PAICODING_OSS_SK\",\n    \"PAICODING_OSS_ENDPOINT\",\n    \"PAICODING_OSS_BUCKET\",\n    \"PAICODING_OSS_HOST\",\n  ];\n  const missing = required.filter((key) => !config[key]);\n  if (missing.length > 0) {\n    throw new Error(`Missing required env vars: ${missing.join(\", \")}`);\n  }\n}\n\nfunction collectMarkdownFiles(targets) {\n  const files = [];\n  for (const target of targets) {\n    if (!fs.existsSync(target)) {\n      throw new Error(`Path not found: ${target}`);\n    }\n    const stat = fs.statSync(target);\n    if (stat.isDirectory()) {\n      walkDir(target, files);\n    } else if (target.endsWith(\".md\")) {\n      files.push(target);\n    }\n  }\n  return [...new Set(files)].sort();\n}\n\nfunction walkDir(dir, files) {\n  const entries = fs.readdirSync(dir, { withFileTypes: true });\n  for (const entry of entries) {\n    const fullPath = path.join(dir, entry.name);\n    const relativePath = path.relative(ROOT_DIR, fullPath);\n    if (entry.isDirectory()) {\n      if (!shouldSkipDir(relativePath)) {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/itwanger/toBeBetterJavaer/blob/6617f5fd0b0597735bdc028f2fcd036817877327/scripts/convert-mdnice-images-to-cdn.js#L158-L194","documentation":"Thrown by collectMarkdownFiles() in scripts/convert-mdnice-images-to-cdn.js when a positional target (or the default docs/src) does not exist on disk. Targets are resolved to absolute paths against the repo root before the existence check, so relative paths are interpreted from the repo root, not the current working directory.","triggerScenarios":"`node scripts/convert-mdnice-images-to-cdn.js docs/src/some/typo.md`; passing a relative path like `./docs` which resolves to <repo-root>/./docs — usually fine, but `../docs` or a path from a different cwd breaks; the default target docs/src missing because the script is run outside a full checkout.","commonSituations":"Running the script from a different directory with a cwd-relative path in mind; typos in file/dir names; passing a path with a trailing typo or wrong case on case-sensitive filesystems; repo layout changed.","solutions":["Check the path exists: `ls <repo-root>/<your-target>` and fix the typo","Pass paths relative to the repo root (path.resolve(ROOT_DIR, arg)) or absolute paths","Run with no targets to use the default docs/src and confirm the baseline works"],"exampleFix":"# before\nnode scripts/convert-mdnice-images-to-cdn.js docss/src\n\n# after\nnode scripts/convert-mdnice-images-to-cdn.js docs/src","handlingStrategy":"validation","validationCode":"const target = path.resolve(REPO_ROOT, userArg);\nif (!fs.existsSync(target)) { console.error(`No such path (resolved to ${target}; paths resolve from the repo root): ${userArg}`); process.exit(2); }","typeGuard":"const isExistingPath = (p) => fs.existsSync(path.resolve(REPO_ROOT, p));","tryCatchPattern":"catch (err) { if (err.message.startsWith(\"Path not found:\")) { console.error(\"Path resolves against the repo root — check spelling and base dir\"); process.exit(2); } throw err; }","preventionTips":["Tab-complete paths in the shell instead of typing them","Remember targets resolve from the repo root regardless of cwd","Run with no targets first to confirm the default docs/src works"],"tags":["filesystem","cli","usage-error"],"backgroundTag":null,"analyzedSha":"6617f5fd0b0597735bdc028f2fcd036817877327","analyzedAt":"2026-08-14T14:50:55.107Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}