Skip to content

Commit 5ee21cb

Browse files
committed
fix: fail fast, fail loudly — no silent catch{} on data loading
1 parent 95823b1 commit 5ee21cb

1 file changed

Lines changed: 17 additions & 39 deletions

File tree

docs/data/census.data.ts

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ interface FeatureMeta {
8383
}
8484

8585
function loadFeatureDescriptions(): Record<string, FeatureMeta> {
86-
try {
87-
const path = join(__dirname, "..", "..", "features.json")
86+
const path = join(__dirname, "..", "..", "features.json")
87+
if (!existsSync(path)) {
88+
throw new Error(`features.json not found at ${path}`)
89+
}
90+
{
8891
const raw = JSON.parse(readFileSync(path, "utf-8"))
8992
delete raw.$comment
9093
// Normalize: strings become { name: string }, objects stay as-is
@@ -97,48 +100,23 @@ function loadFeatureDescriptions(): Record<string, FeatureMeta> {
97100
}
98101
}
99102
return result
100-
} catch {
101-
return {}
102103
}
103104
}
104105

105106
function loadAnnotations(): Record<string, { note: string; url?: string }> {
106-
try {
107-
const annotationsPath = join(__dirname, "..", "..", "annotations.json")
108-
return JSON.parse(readFileSync(annotationsPath, "utf-8"))
109-
} catch {
110-
return {}
107+
const annotationsPath = join(__dirname, "..", "..", "annotations.json")
108+
if (!existsSync(annotationsPath)) {
109+
throw new Error(`annotations.json not found at ${annotationsPath}`)
111110
}
111+
return JSON.parse(readFileSync(annotationsPath, "utf-8"))
112112
}
113113

114114
function loadBackendMeta(): Record<string, BackendMeta> {
115-
// Primary: backends-meta.json (always available, even in CI)
116-
try {
117-
const metaPath = join(__dirname, "..", "..", "backends-meta.json")
118-
const raw = JSON.parse(readFileSync(metaPath, "utf-8"))
119-
return raw as Record<string, BackendMeta>
120-
} catch {}
121-
122-
// Fallback: @termless/core manifest
123-
if (!manifest) return {}
124-
try {
125-
const m = manifest()
126-
const meta: Record<string, BackendMeta> = {}
127-
for (const [name, entry] of Object.entries(m.backends) as [string, any][]) {
128-
meta[name] = {
129-
label: entry.label,
130-
description: entry.description,
131-
url: entry.url,
132-
upstream: entry.upstream ?? undefined,
133-
type: entry.type,
134-
caveat: entry.caveat,
135-
slug: entry.slug,
136-
}
137-
}
138-
return meta
139-
} catch {
140-
return {}
115+
const metaPath = join(__dirname, "..", "..", "backends-meta.json")
116+
if (!existsSync(metaPath)) {
117+
throw new Error(`backends-meta.json not found at ${metaPath}. Copy from termless: python3 -c "..."`)
141118
}
119+
return JSON.parse(readFileSync(metaPath, "utf-8")) as Record<string, BackendMeta>
142120
}
143121

144122
declare const data: CensusData
@@ -234,8 +212,8 @@ function loadPerBackendResults(): CensusData {
234212
let files: string[]
235213
try {
236214
files = readdirSync(resultsDir).filter((f) => f.endsWith(".json") && f !== "census.json")
237-
} catch {
238-
return emptyData()
215+
} catch (err) {
216+
throw new Error(`Failed to read census results from ${resultsDir}: ${err}`)
239217
}
240218

241219
if (files.length === 0) return emptyData()
@@ -274,8 +252,8 @@ function loadPerBackendResults(): CensusData {
274252
})
275253
}
276254
}
277-
} catch {
278-
// skip malformed
255+
} catch (err) {
256+
throw new Error(`Failed to parse census result ${file}: ${err}`)
279257
}
280258
}
281259

0 commit comments

Comments
 (0)