Skip to content

Commit 0f05123

Browse files
committed
read config in try/catch
1 parent ddc91a4 commit 0f05123

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/utils/fs.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,15 @@ export async function readConfigFile(filePath: string, contextWindow: number): P
4949
* @returns The parsed configuration object
5050
*/
5151
export async function readJsonConfigFile<T>(filePath: string, contextWindow: number): Promise<T> {
52-
const content = await readConfigFile(filePath, contextWindow)
53-
return JSON.parse(content) as T
52+
try {
53+
const content = await readConfigFile(filePath, contextWindow)
54+
return JSON.parse(content) as T
55+
} catch (error) {
56+
if (error instanceof SyntaxError) {
57+
throw new Error(`Invalid JSON in config file ${filePath}: ${error.message}`)
58+
}
59+
throw new Error(`Failed to read config file ${filePath}: ${error instanceof Error ? error.message : String(error)}`)
60+
}
5461
}
5562

5663
/**

0 commit comments

Comments
 (0)