Skip to content

Commit 0c26cd0

Browse files
committed
docs(cli): document error handling strategy in checkup module
Address code review feedback: add documentation explaining the two error handling patterns used in the module: - Propagating: core data functions throw on error (report should fail) - Graceful degradation: optional queries catch errors (include in output) Also add JSDoc @throws annotations to key functions.
1 parent 6a9d0e3 commit 0c26cd0

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

cli/lib/checkup.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@
2222
* Before adding or modifying a report, verify the corresponding schema exists
2323
* and ensure the output matches. Run schema validation tests to confirm.
2424
*
25+
* 3. ERROR HANDLING STRATEGY
26+
* Functions follow two patterns based on criticality:
27+
*
28+
* PROPAGATING (throws on error):
29+
* - Core data functions: getPostgresVersion, getSettings, getAlteredSettings,
30+
* getDatabaseSizes, getInvalidIndexes, getUnusedIndexes, getRedundantIndexes
31+
* - If these fail, the entire report should fail (data is required)
32+
* - Callers should handle errors at the report generation level
33+
*
34+
* GRACEFUL DEGRADATION (catches errors, includes error in output):
35+
* - Optional/supplementary queries: pg_stat_statements, pg_stat_kcache checks,
36+
* memory calculations, postmaster startup time
37+
* - These are nice-to-have; missing data shouldn't fail the whole report
38+
* - Errors are logged and included in report output for visibility
39+
*
2540
* ADDING NEW REPORTS
2641
* ------------------
2742
* 1. Add/verify the metric exists in config/pgwatch-prometheus/metrics.yml
@@ -247,8 +262,10 @@ function formatSettingPrettyValue(
247262
}
248263

249264
/**
250-
* Get PostgreSQL version information
251-
* Uses simple inline SQL (trivial query, CLI-specific)
265+
* Get PostgreSQL version information.
266+
* Uses simple inline SQL (trivial query, CLI-specific).
267+
*
268+
* @throws {Error} If database query fails (propagating - critical data)
252269
*/
253270
export async function getPostgresVersion(client: Client): Promise<PostgresVersion> {
254271
const result = await client.query(`
@@ -967,7 +984,11 @@ export async function generateH004(client: Client, nodeName: string = "node-01")
967984
}
968985

969986
/**
970-
* Generate D004 report - pg_stat_statements and pg_stat_kcache settings
987+
* Generate D004 report - pg_stat_statements and pg_stat_kcache settings.
988+
*
989+
* Uses graceful degradation: extension queries are wrapped in try-catch
990+
* because extensions may not be installed. Errors are included in the
991+
* report output rather than failing the entire report.
971992
*/
972993
async function generateD004(client: Client, nodeName: string): Promise<Report> {
973994
const report = createBaseReport("D004", "pg_stat_statements and pg_stat_kcache settings", nodeName);

0 commit comments

Comments
 (0)