{"record":{"id":"91912c51cb41cd38","repo":"jackwener/OpenCLI","slug":"failed-to-scan-filepath-geterrormessage-caus","errorCode":null,"errorMessage":"failed to scan ${filePath}: ${getErrorMessage(cause)}","messagePattern":"failed to scan (.+?): (.+?)","errorType":"exception","errorClass":"ManifestImportError","httpStatus":null,"severity":"error","filePath":"src/build-manifest.ts","lineNumber":156,"sourceCode":" * Throws `ManifestImportError` when a file looks like a CLI module but its\n * import or post-import processing fails — callers must decide whether to\n * surface or aggregate the failure.\n *\n * The third argument `clisDir` is used to compute the POSIX-style\n * `sourceFile` relative path; it defaults to the package's `clis/` dir so\n * existing test callers stay backward-compatible.\n */\nexport async function loadManifestEntries(\n  filePath: string,\n  site: string,\n  importer: (moduleHref: string) => Promise<unknown> = moduleHref => import(moduleHref),\n  clisDir: string = CLIS_DIR,\n): Promise<ManifestEntry[]> {\n  let src: string;\n  try {\n    src = fs.readFileSync(filePath, 'utf-8');\n  } catch (err) {\n    throw new ManifestImportError(filePath, err);\n  }\n\n  // Helper / test modules that do not call cli() are not commands.\n  if (!CLI_MODULE_PATTERN.test(src)) return [];\n\n  try {\n    const modulePath = toModulePath(filePath, site);\n    const registry = getRegistry();\n    const before = new Map(registry.entries());\n    const mod = await importer(pathToFileURL(filePath).href);\n\n    const exportedCommands = Object.values(isRecord(mod) ? mod : {})\n      .filter(value => isCliCommandValue(value, site));\n\n    const runtimeCommands = exportedCommands.length > 0\n      ? exportedCommands\n      : [...registry.entries()]\n        .filter(([key, cmd]) => {","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/src/build-manifest.ts#L138-L174","documentation":"loadManifestEntries reads a CLI adapter module from clis/ to extract command definitions for the build manifest. If the file cannot be read from disk, it throws a ManifestImportError naming the file and the underlying cause, aborting that scan with a clear message instead of a raw fs error.","triggerScenarios":"fs.readFileSync fails on the module path — file deleted between discovery and read, wrong clisDir passed, case-mismatched filename on case-sensitive filesystems, or permission denied.","commonSituations":"Renaming/deleting a clis/*.ts file while a build runs; running the manifest build from a different working directory so the relative clis dir doesn't resolve; symlinked repos where CLIS_DIR points elsewhere.","solutions":["Confirm the file at filePath exists and is readable (ls -l, check permissions).","Run the manifest build from the repository root so the default CLIS_DIR resolves correctly.","Restore the deleted/renamed module or update the scanner's directory configuration.","If on Linux/macOS, check filename casing matches the import/discovery path exactly."],"exampleFix":"// before\nbuildManifest({ clisDir: path.join(process.cwd(), 'Cli') });\n// after\nbuildManifest({ clisDir: path.join(process.cwd(), 'clis') });","handlingStrategy":"try-catch","validationCode":"import { accessSync, constants } from 'fs';\nfunction canRead(p) { try { accessSync(p, constants.R_OK); return true; } catch { return false; } }","typeGuard":"function isManifestImportError(e: unknown): e is ManifestImportError {\n  return e instanceof Error && 'filePath' in e;\n}","tryCatchPattern":"try {\n  const entries = await loadManifestEntries(filePath);\n} catch (err) {\n  if (err instanceof ManifestImportError) {\n    console.error(`skipping unreadable module ${err.filePath}:`, err.cause);\n    return [];\n  }\n  throw err;\n}","preventionTips":["Run manifest builds from the repository root so CLIS_DIR resolves.","Don't delete or rename clis/ modules while a build is running.","Keep filename casing consistent across platforms.","Check file permissions in CI (run as a user that can read the repo)."],"tags":["filesystem","build","manifest","read-file"],"backgroundTag":"file-read-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}