Handle missing selected workspace files

This commit is contained in:
Federico Jaramillo Martinez
2026-05-11 10:41:33 +02:00
parent 1ae43998e7
commit 045f4e247a
4 changed files with 24 additions and 2 deletions
+8 -1
View File
@@ -5,7 +5,10 @@ export async function resolveInsideWorkspace(rootPath: string, relativePath: str
const requested = normalizeRelativePath(relativePath);
const root = await realpath(rootPath);
const joined = join(root, requested);
const target = await realpath(joined);
const target = await realpath(joined).catch((error: unknown) => {
if (isNodeErrorWithCode(error, "ENOENT")) throw new Error("Path does not exist");
throw error;
});
ensureInside(root, target);
return { root, target, relativePath: requested };
}
@@ -27,6 +30,10 @@ export function normalizeRelativePath(input: string | undefined): string {
return parts.join("/");
}
function isNodeErrorWithCode(error: unknown, code: string): error is NodeJS.ErrnoException {
return typeof error === "object" && error !== null && "code" in error && error.code === code;
}
function ensureInside(root: string, target: string): void {
const rel = relative(root, target);
if (rel === "") return;