Merge pull request #1359 from jbrahy/fix/loadfile-eisdir-guard

fix: avoid EISDIR crash in GSD file loader
This commit is contained in:
TÂCHES 2026-03-19 16:38:11 -06:00 committed by GitHub
commit d3d682cf00
2 changed files with 22 additions and 1 deletions

View file

@ -590,7 +590,8 @@ export async function loadFile(path: string): Promise<string | null> {
try {
return await fs.readFile(path, 'utf-8');
} catch (err: unknown) {
if ((err as NodeJS.ErrnoException).code === 'ENOENT') return null;
const code = (err as NodeJS.ErrnoException).code;
if (code === 'ENOENT' || code === 'EISDIR') return null;
throw err;
}
}

View file

@ -0,0 +1,20 @@
import test from "node:test";
import assert from "node:assert/strict";
import os from "node:os";
import path from "node:path";
import fs from "node:fs";
import { loadFile } from "../files.ts";
test("loadFile returns null for directory paths instead of throwing EISDIR", async () => {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "gsd-loadfile-eisdir-"));
const dirPath = path.join(tmp, "tasks");
fs.mkdirSync(dirPath);
try {
const result = await loadFile(dirPath);
assert.equal(result, null);
} finally {
fs.rmSync(tmp, { recursive: true, force: true });
}
});