Skip to content

Commit 5c054c0

Browse files
committed
fix(@angular/cli): handle errors from isAllowedWorkspacePath in best-practices tool
isAllowedWorkspacePath can throw if the workspace path does not exist (realpathSync) or if listRoots() fails against the connected client. Wrap the check in a try-catch and fall back to the bundled guide on any failure, matching this function's existing fallback behavior.
1 parent a71bb31 commit 5c054c0

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

packages/angular/cli/src/commands/mcp/tools/best-practices.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,24 @@ async function getVersionSpecificBestPractices(
9696
logger: McpToolContext['logger'],
9797
server: McpToolContext['server'],
9898
): Promise<{ content: string; source: string } | undefined> {
99-
if (server && !(await isAllowedWorkspacePath(server, workspacePath))) {
100-
logger.warn(
101-
`Workspace path is outside the allowed MCP roots: ${workspacePath}. ` +
102-
'Falling back to the bundled guide.',
103-
);
99+
if (server) {
100+
try {
101+
if (!(await isAllowedWorkspacePath(server, workspacePath))) {
102+
logger.warn(
103+
`Workspace path is outside the allowed MCP roots: ${workspacePath}. ` +
104+
'Falling back to the bundled guide.',
105+
);
104106

105-
return undefined;
107+
return undefined;
108+
}
109+
} catch (e) {
110+
logger.warn(
111+
`Failed to verify workspace path '${workspacePath}': ` +
112+
`${e instanceof Error ? e.message : e}. Falling back to the bundled guide.`,
113+
);
114+
115+
return undefined;
116+
}
106117
}
107118

108119
// 1. Resolve the path to package.json

0 commit comments

Comments
 (0)