Skip to content

Commit dbb46a5

Browse files
Improve error handling in check script
- Distinguish ENOENT from EACCES and other I/O errors instead of treating all failures as 'missing' - Log errors to stderr with descriptive messages - Validate JSON files parse correctly - Detect empty files - Report total failure count on exit Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 833074e commit dbb46a5

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

scripts/check.mjs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,37 @@ const required = [
1313
let failed = 0;
1414
for (const file of required) {
1515
try {
16-
await readFile(new URL(`../${file}`, import.meta.url), "utf8");
16+
const content = await readFile(new URL(`../${file}`, import.meta.url), "utf8");
17+
if (!content.trim()) {
18+
failed += 1;
19+
console.error(`empty ${file}`);
20+
continue;
21+
}
22+
if (file.endsWith(".json")) {
23+
try {
24+
JSON.parse(content);
25+
} catch (parseErr) {
26+
failed += 1;
27+
console.error(`invalid json ${file}: ${parseErr.message}`);
28+
continue;
29+
}
30+
}
1731
console.log(`ok ${file}`);
18-
} catch {
32+
} catch (err) {
1933
failed += 1;
20-
console.log(`missing ${file}`);
34+
if (err.code === "ENOENT") {
35+
console.error(`missing ${file}`);
36+
} else if (err.code === "EACCES") {
37+
console.error(`permission denied ${file}: ${err.message}`);
38+
} else {
39+
console.error(`error reading ${file}: ${err.message}`);
40+
}
2141
}
2242
}
2343

24-
if (failed) process.exit(1);
44+
if (failed) {
45+
console.error(`\n${failed} file(s) failed checks`);
46+
process.exit(1);
47+
}
2548
console.log("graphite incubator check passed");
2649

0 commit comments

Comments
 (0)