Skip to content

Commit 86d1c74

Browse files
committed
feat(cli): include parse error in H004 redundant index output
- Added optional redundant_to_parse_error field to RedundantIndex - Errors now captured in report output (not just console log) - Makes data quality issues visible in report JSON - Updated H004 schema to allow the new optional field
1 parent 632daa4 commit 86d1c74

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

cli/lib/checkup.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ export interface RedundantIndex {
167167
index_size_pretty: string;
168168
table_size_pretty: string;
169169
redundant_to: RedundantToIndex[];
170+
/** Set when redundant_to_json parsing fails - indicates data quality issue */
171+
redundant_to_parse_error?: string;
170172
}
171173

172174
/**
@@ -685,6 +687,7 @@ export async function getRedundantIndexes(client: Client, pgMajorVersion: number
685687

686688
// Parse redundant_to JSON array (indexes that make this one redundant)
687689
let redundantTo: RedundantToIndex[] = [];
690+
let parseError: string | undefined;
688691
try {
689692
const jsonStr = String(transformed.redundant_to_json || "[]");
690693
const parsed = JSON.parse(jsonStr);
@@ -704,10 +707,11 @@ export async function getRedundantIndexes(client: Client, pgMajorVersion: number
704707
} catch (err) {
705708
const errorMsg = err instanceof Error ? err.message : String(err);
706709
const indexName = String(transformed.index_name || "unknown");
707-
console.log(`[H004] Warning: Failed to parse redundant_to_json for index "${indexName}": ${errorMsg}`);
710+
parseError = `Failed to parse redundant_to_json: ${errorMsg}`;
711+
console.log(`[H004] Warning: ${parseError} for index "${indexName}"`);
708712
}
709713

710-
return {
714+
const result: RedundantIndex = {
711715
schema_name: String(transformed.schema_name || ""),
712716
table_name: String(transformed.table_name || ""),
713717
index_name: String(transformed.index_name || ""),
@@ -723,6 +727,13 @@ export async function getRedundantIndexes(client: Client, pgMajorVersion: number
723727
table_size_pretty: formatBytes(tableSizeBytes),
724728
redundant_to: redundantTo,
725729
};
730+
731+
// Only include parse error field if there was an error (keeps output clean)
732+
if (parseError) {
733+
result.redundant_to_parse_error = parseError;
734+
}
735+
736+
return result;
726737
});
727738
}
728739

reporter/schemas/H004.schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
"index_definition": { "type": "string" },
8484
"index_size_pretty": { "type": "string" },
8585
"table_size_pretty": { "type": "string" },
86-
"redundant_to": { "type": "array", "items": { "$ref": "#/$defs/redundantToIndex" } }
86+
"redundant_to": { "type": "array", "items": { "$ref": "#/$defs/redundantToIndex" } },
87+
"redundant_to_parse_error": { "type": "string" }
8788
}
8889
},
8990
"dbEntry": {

0 commit comments

Comments
 (0)