Compare commits

...
Author SHA1 Message Date
Sonarly Claude CodeandClaude Opus 4.6 fad1ee04ee fix: add error handling to objectRecordCounts resolver and harden SQL query
The objectRecordCounts resolver was missing try-catch error handling,
unlike all other methods in ObjectMetadataResolver. Any error thrown
by getRecordCounts() (database issues, cache failures, etc.) would
propagate as an unhandled exception, creating Sentry issues.

Changes:
- Add try-catch with objectMetadataGraphqlApiExceptionHandler to the
  objectRecordCounts resolver, matching the pattern of all other methods
- Add @Context() decorator to access i18n for proper error messages
- Harden SQL query to filter out tables with reltuples < 0 (unanalyzed
  tables in PG14+) and use GREATEST(0, reltuples) to prevent negative
  values from reaching the bigint cast

Sentry issue: https://sentry.io/issues/7117135856/

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 03:16:56 +00:00
2 changed files with 14 additions and 3 deletions
@@ -52,8 +52,18 @@ export class ObjectMetadataResolver {
@Query(() => [ObjectRecordCountDTO])
async objectRecordCounts(
@AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
@Context() context: I18nContext,
): Promise<ObjectRecordCountDTO[]> {
return this.objectRecordCountService.getRecordCounts(workspaceId);
try {
return await this.objectRecordCountService.getRecordCounts(workspaceId);
} catch (error) {
objectMetadataGraphqlApiExceptionHandler(
error,
this.i18nService.getI18nInstance(context.req.locale),
);
return [];
}
}
@ResolveField(() => String, { nullable: true })
@@ -35,11 +35,12 @@ export class ObjectRecordCountService {
const rows: { relname: string; approximate_count: number }[] =
await dataSource.query(
`SELECT relname, reltuples::bigint AS approximate_count
`SELECT relname, GREATEST(0, reltuples)::bigint AS approximate_count
FROM pg_class c
JOIN pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = $1
AND c.relkind = 'r'`,
AND c.relkind = 'r'
AND reltuples >= 0`,
[schemaName],
undefined,
{ shouldBypassPermissionChecks: true },