From 5f8c9b8514a7aead0e44eb3e9094cf64b8f80c9e Mon Sep 17 00:00:00 2001 From: Tang Vu Date: Thu, 19 Mar 2026 00:49:44 +0700 Subject: [PATCH] refactor: missing error handling for json.parse `JSON.parse(row.result)` is called without a try-catch block. If the database contains invalid JSON in this column, it will throw an exception and crash the `getBenchmarks` function, breaking the page. Affected files: index.tsx --- .../console/app/src/routes/bench/index.tsx | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/packages/console/app/src/routes/bench/index.tsx b/packages/console/app/src/routes/bench/index.tsx index 9b8d0b8f24f..9ead9caa1be 100644 --- a/packages/console/app/src/routes/bench/index.tsx +++ b/packages/console/app/src/routes/bench/index.tsx @@ -3,6 +3,7 @@ import { A, createAsync, query } from "@solidjs/router" import { createMemo, For, Show } from "solid-js" import { Database, desc } from "@opencode-ai/console-core/drizzle/index.js" import { BenchmarkTable } from "@opencode-ai/console-core/schema/benchmark.sql.js" +import { useI18n } from "~/context/i18n" interface BenchmarkResult { averageScore: number @@ -14,18 +15,25 @@ async function getBenchmarks() { const rows = await Database.use((tx) => tx.select().from(BenchmarkTable).orderBy(desc(BenchmarkTable.timeCreated)).limit(100), ) - return rows.map((row) => { - const parsed = JSON.parse(row.result) as BenchmarkResult - const taskScores: Record = {} - for (const t of parsed.tasks) { - taskScores[t.task.id] = t.averageScore - } - return { - id: row.id, - agent: row.agent, - model: row.model, - averageScore: parsed.averageScore, - taskScores, + return rows.flatMap((row) => { + try { + const parsed = JSON.parse(row.result) as BenchmarkResult + const taskScores: Record = {} + for (const t of parsed.tasks) { + taskScores[t.task.id] = t.averageScore + } + return [ + { + id: row.id, + agent: row.agent, + model: row.model, + averageScore: parsed.averageScore, + taskScores, + }, + ] + } catch (error) { + console.error(`Failed to parse benchmark result for row ${row.id}:`, error) + return [] } }) } @@ -33,6 +41,7 @@ async function getBenchmarks() { const queryBenchmarks = query(getBenchmarks, "benchmarks.list") export default function Bench() { + const i18n = useI18n() const benchmarks = createAsync(() => queryBenchmarks()) const taskIds = createMemo(() => { @@ -47,14 +56,14 @@ export default function Bench() { return (
- Benchmark -

Benchmarks

+ {i18n.t("bench.list.title")} +

{i18n.t("bench.list.heading")}

- - - + + + {(id) => }
AgentModelScore{i18n.t("bench.list.table.agent")}{i18n.t("bench.list.table.model")}{i18n.t("bench.list.table.score")} {id}