Skip to content

Commit d93da6a

Browse files
committed
insights: better logging when sending a q-manifest
1 parent 07593c8 commit d93da6a

File tree

1 file changed

+41
-1
lines changed
  • packages/insights/src/routes/api/v1/[publicApiKey]/post/manifest

1 file changed

+41
-1
lines changed

packages/insights/src/routes/api/v1/[publicApiKey]/post/manifest/index.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export const onPost: RequestHandler = async ({ exit, json, request, params }) =>
1010
try {
1111
const qManifest = QManifest.parse(await request.json());
1212
const manifestHash = qManifest.manifestHash;
13+
14+
console.log(
15+
`Processing manifest ${manifestHash} for API key ${publicApiKey} with ${Object.keys(qManifest.symbols).length} symbols`
16+
);
17+
1318
exit();
1419
const db = getDB();
1520
await dbGetManifestInfo(db, publicApiKey, manifestHash);
@@ -24,9 +29,16 @@ export const onPost: RequestHandler = async ({ exit, json, request, params }) =>
2429
)
2530
.limit(1000)
2631
.all();
32+
33+
console.log(`Found ${existing.length} existing symbols for manifest ${manifestHash}`);
34+
2735
const existingMap = new Map<string, (typeof existing)[0]>();
2836
existing.forEach((row) => existingMap.set(row.hash, row));
2937
const promises: Promise<any>[] = [];
38+
39+
let insertCount = 0;
40+
let updateCount = 0;
41+
3042
for (const symbol of Object.values(qManifest.symbols)) {
3143
const existing = existingMap.get(symbol.hash);
3244
const lo = symbol.loc[0];
@@ -38,6 +50,7 @@ export const onPost: RequestHandler = async ({ exit, json, request, params }) =>
3850
existing.lo !== lo ||
3951
existing.hi !== hi
4052
) {
53+
updateCount++;
4154
promises.push(
4255
db
4356
.update(symbolDetailTable)
@@ -49,9 +62,14 @@ export const onPost: RequestHandler = async ({ exit, json, request, params }) =>
4962
})
5063
.where(eq(symbolDetailTable.id, existing.id))
5164
.run()
65+
.catch((error) => {
66+
console.error(`Failed to update symbol ${symbol.hash}:`, error);
67+
throw error;
68+
})
5269
);
5370
}
5471
} else {
72+
insertCount++;
5573
promises.push(
5674
db
5775
.insert(symbolDetailTable)
@@ -65,6 +83,20 @@ export const onPost: RequestHandler = async ({ exit, json, request, params }) =>
6583
hi,
6684
})
6785
.run()
86+
.catch((error) => {
87+
console.error(
88+
`Failed to insert symbol ${symbol.hash} for manifest ${manifestHash}:`,
89+
{
90+
error: error.message,
91+
symbol: {
92+
hash: symbol.hash,
93+
displayName: symbol.displayName,
94+
origin: symbol.origin,
95+
},
96+
}
97+
);
98+
throw error;
99+
})
68100
);
69101
}
70102
if (promises.length > 10) {
@@ -73,9 +105,17 @@ export const onPost: RequestHandler = async ({ exit, json, request, params }) =>
73105
}
74106
}
75107
await Promise.all(promises);
108+
109+
console.log(
110+
`Successfully processed manifest ${manifestHash}: ${insertCount} inserts, ${updateCount} updates`
111+
);
76112
json(200, { code: 200, message: 'OK' });
77113
} catch (e) {
78-
console.error(JSON.stringify(e));
114+
console.error(`Error processing manifest for API key ${publicApiKey}:`, {
115+
error: e instanceof Error ? e.message : String(e),
116+
stack: e instanceof Error ? e.stack : undefined,
117+
publicApiKey,
118+
});
79119
json(500, { code: 500, message: 'Internal Server Error', error: e });
80120
}
81121
};

0 commit comments

Comments
 (0)