Skip to content

Commit b30de5b

Browse files
committed
fix: reading JSON string from service_usage_monthly
This was hilariously difficult to debug. This isn't the first time an issue like this occurred; this happens because of a deviation between mysql and sqlite, where a JSON-typed column in mysql will return as a native object in queries, whereas a JSON-typed column in sqlite is a string column and will therefore return as an un-parsed JSON string in queries.
1 parent 7ba16d1 commit b30de5b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/backend/src/routers/drivers/usage.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,18 @@ module.exports = eggspress('/drivers/usage', {
6060

6161
for ( const row of rows ) {
6262
const app = await get_app({ id: row.app_id });
63-
63+
6464
let extra_parsed;
6565
try {
66-
extra_parsed = JSON.parse(row.extra);
66+
extra_parsed = db.case({
67+
mysql: () => row.extra,
68+
otherwise: () => JSON.parse(row.extra),
69+
})();
6770
} catch ( e ) {
71+
console.log(
72+
'\x1B[31;1m error parsing monthly usage extra',
73+
row.extra, e,
74+
);
6875
continue;
6976
}
7077

0 commit comments

Comments
 (0)