fix(memory): preserve ENOTDIR missing reads

Signed-off-by: samzong <samzong.lu@gmail.com>
This commit is contained in:
samzong
2026-05-11 00:50:34 +08:00
committed by Peter Steinberger
parent c6748a8eeb
commit 5ad3fa0a17
2 changed files with 15 additions and 1 deletions

View File

@@ -18,12 +18,13 @@ if (!hasPythonModeOverride) {
export function isFileMissingError(
err: unknown,
): err is NodeJS.ErrnoException & { code: "ENOENT" } {
): err is NodeJS.ErrnoException & { code: "ENOENT" | "ENOTDIR" | "not-found" } {
return Boolean(
err &&
typeof err === "object" &&
"code" in err &&
((err as Partial<NodeJS.ErrnoException>).code === "ENOENT" ||
(err as Partial<NodeJS.ErrnoException>).code === "ENOTDIR" ||
(err as { code?: unknown }).code === "not-found"),
);
}

View File

@@ -37,6 +37,19 @@ describe("readMemoryFile", () => {
text: "",
path: path.relative(workspaceDir, missingPath).replace(/\\/g, "/"),
});
const nonDirectoryParentPath = path.join(extraDir, "note.md", "child.md");
await fs.writeFile(path.join(extraDir, "note.md"), "note", "utf-8");
await expect(
readMemoryFile({
workspaceDir,
extraPaths: [extraDir],
relPath: nonDirectoryParentPath,
}),
).resolves.toEqual({
text: "",
path: path.relative(workspaceDir, nonDirectoryParentPath).replace(/\\/g, "/"),
});
} finally {
await fs.rm(tmpRoot, { recursive: true, force: true });
}