MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / readJsonOrNull

Function readJsonOrNull

src/tools/codegraph/project-overview.ts:142–152  ·  view source on GitHub ↗

* Reads + parses a JSON config. Returns null when the file is simply absent * (ENOENT), but on a real parse failure logs a warning and records the path in * `unparseable` so the caller can surface the corruption instead of silently * misreporting the tech stack as "config absent".

(filePath: string, unparseable?: string[])

Source from the content-addressed store, hash-verified

140 * misreporting the tech stack as "config absent".
141 */
142async function readJsonOrNull(filePath: string, unparseable?: string[]): Promise<any> {
143 try {
144 return JSON.parse(await fs.readFile(filePath, 'utf-8'));
145 } catch (err: any) {
146 if (err?.code !== 'ENOENT') {
147 logger.warn(`Failed to parse ${filePath}: ${err?.message ?? err}`);
148 unparseable?.push(filePath);
149 }
150 return null;
151 }
152}
153
154export class ProjectOverviewTool extends Tool<z.infer<typeof ProjectOverviewArgs>> {
155 name = 'project_overview';

Callers 1

executeMethod · 0.70

Calls 2

warnMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected