Skip to content

Commit 6f529e5

Browse files
committed
fix: crash when cmd private is not found on start
1 parent 4cdc36d commit 6f529e5

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

src/components/utils/cmd/loader.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,28 @@ export async function mapCommands() {
9494
let allFiles: [string, string][] = [];
9595

9696
for (const dir of commandDirs) {
97-
const files = await fs.readdir(dir);
97+
try {
98+
await fs.access(dir);
99+
const files = await fs.readdir(dir);
98100

99-
const validFiles = files.filter(
100-
(f) => f.endsWith(".js") || f.endsWith(".ts"),
101-
);
101+
const validFiles = files.filter(
102+
(f) => f.endsWith(".js") || f.endsWith(".ts"),
103+
);
102104

103-
const tuples: [string, string][] = validFiles.map(
104-
(f) => [f, dir] as [string, string],
105-
);
105+
const tuples: [string, string][] = validFiles.map(
106+
(f) => [f, dir] as [string, string],
107+
);
106108

107-
allFiles = [...allFiles, ...tuples];
109+
allFiles = [...allFiles, ...tuples];
110+
} catch (err: any) {
111+
if (err.code === "ENOENT") {
112+
console.log("")
113+
log.warn("Loader", `Directory not found: ${dir}`);
114+
} else {
115+
console.log("")
116+
log.warn("Loader", `Error reading directory ${dir}:`, err);
117+
}
118+
}
108119
}
109120

110121
const total = allFiles.length;

0 commit comments

Comments
 (0)