{"record":{"id":"fd6c1e43e2b8cb27","repo":"angular/angular-cli","slug":"failed-to-access-path-fileordirpath","errorCode":null,"errorMessage":"Failed to access path: ${fileOrDirPath}","messagePattern":"Failed to access path: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.ts","lineNumber":129,"sourceCode":"}\n\nasync function discoverAndCategorizeFiles(\n  fileOrDirPath: string,\n  host: Host,\n  extras: ServerContext,\n) {\n  const filePaths: string[] = [];\n  const componentTestFiles = new Set<SourceFile>();\n  const filesWithComponents = new Set<SourceFile>();\n  const zoneFiles = new Set<SourceFile>();\n  const categorizationErrors: { filePath: string; message: string }[] = [];\n\n  let isDirectory: boolean;\n  try {\n    isDirectory = (await host.stat(fileOrDirPath)).isDirectory();\n  } catch (e) {\n    // Re-throw to be handled by the main function as a user input error\n    throw new Error(`Failed to access path: ${fileOrDirPath}`, { cause: e });\n  }\n\n  if (isDirectory) {\n    const files = host.glob('**/*.ts', { cwd: fileOrDirPath });\n    for await (const file of files) {\n      filePaths.push(join(file.parentPath, file.name));\n    }\n  } else {\n    filePaths.push(fileOrDirPath);\n    const maybeTestFile = await getTestFilePath(fileOrDirPath, host);\n    if (maybeTestFile) {\n      // Eagerly add the test file path for categorization.\n      filePaths.push(maybeTestFile);\n    }\n  }\n\n  const CONCURRENCY_LIMIT = 50;\n  const filesToProcess = [...filePaths];","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.ts#L111-L147","documentation":"In discoverAndCategorizeFiles, the tool stats the user-supplied path via the virtual file host to decide whether it is a file or directory. If stat() fails (path does not exist or is not readable), the error is wrapped as 'Failed to access path: <path>' with the original error as cause, to be surfaced as a user input error by the caller (the zoneless migration MCP tool).","triggerScenarios":"Calling the zoneless-migration MCP tool with a fileOrDirPath argument that does not exist, is inaccessible due to permissions, or that the virtual host cannot stat. discoverAndCategorizeFiles hits the catch branch at zoneless-migration.ts:129 and re-throws the wrapped Error.","commonSituations":"Typo in the path passed to the migration tool; relative path resolved against the wrong working directory; path exists on disk but outside the host workspace; deleted or moved directory between planning and running the migration.","solutions":["Verify the path exists and is readable (ls the fileOrDirPath) before invoking the tool","Pass an absolute path rooted at the workspace, or run the tool from the correct working directory","Confirm the path is within the MCP server's allowed workspace roots","Check the cause property of the thrown error for the underlying stat failure (ENOENT vs EACCES)"],"exampleFix":"// before\nawait discoverAndCategorizeFiles(host, 'src/app/widget.ts');\n// after\nimport { existsSync, statSync } from 'node:fs';\nconst p = '/abs/path/src/app/widget.ts';\nif (!existsSync(p)) throw new Error(`Path not found: ${p}`);\nawait discoverAndCategorizeFiles(host, p);","handlingStrategy":"validation","validationCode":"import { existsSync, statSync } from 'node:fs';\nif (!existsSync(fileOrDirPath)) {\n  throw new Error(`Path does not exist: ${fileOrDirPath}`);\n}\nstatSync(fileOrDirPath); // also verifies readability","typeGuard":null,"tryCatchPattern":"try {\n  await discoverAndCategorizeFiles(host, p);\n} catch (e) {\n  if ((e as Error).message.startsWith('Failed to access path')) {\n    console.error(`Check the path exists and is accessible: ${(e as Error & { cause?: Error }).cause?.message}`);\n  } else throw e;\n}","preventionTips":["Always pass absolute, verified paths to MCP tools","Run the tool with a working directory matching the workspace root","Check the cause chain to distinguish ENOENT from EACCES"],"tags":["filesystem","invalid-input","path-resolution","angular-cli"],"backgroundTag":"file-or-directory-not-found","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}