guard against errors when there are no results in certain contact queries

This commit is contained in:
2026-01-12 20:14:39 -07:00
parent 662da79df8
commit b6704b348b

View File

@@ -1507,7 +1507,7 @@ export const PlatformServiceMixin = {
"SELECT label FROM contact_labels WHERE did = ? ORDER BY label", "SELECT label FROM contact_labels WHERE did = ? ORDER BY label",
[did], [did],
)) as QueryExecResult; )) as QueryExecResult;
return results.values.map((r: SqlValue[]) => r[0] as string); return results?.values?.map((r: SqlValue[]) => r[0] as string) || [];
} catch (error) { } catch (error) {
logger.error( logger.error(
`[PlatformServiceMixin] Error getting labels for contact ${did}:`, `[PlatformServiceMixin] Error getting labels for contact ${did}:`,
@@ -1531,14 +1531,15 @@ export const PlatformServiceMixin = {
[...labels], [...labels],
)) as QueryExecResult; )) as QueryExecResult;
// count the occurrences of each did // count the occurrences of each did
const didCounts: Record<string, number> = results.values?.reduce( const didCounts: Record<string, number> =
(acc: Record<string, number>, curr: SqlValue[]) => { results?.values?.reduce(
acc[curr[0] as unknown as string] = (acc: Record<string, number>, curr: SqlValue[]) => {
(acc[curr[0] as unknown as string] || 0) + 1; acc[curr[0] as unknown as string] =
return acc; (acc[curr[0] as unknown as string] || 0) + 1;
}, return acc;
{}, },
); {},
) || {};
// filter out the dids that do not occur for as many labels as there are labels // filter out the dids that do not occur for as many labels as there are labels
const contactIdsWithAllLabels = Object.keys(didCounts).filter( const contactIdsWithAllLabels = Object.keys(didCounts).filter(
(did: string) => didCounts[did] === numberOfLabels, (did: string) => didCounts[did] === numberOfLabels,
@@ -1606,7 +1607,7 @@ export const PlatformServiceMixin = {
const results = (await this.$dbQuery( const results = (await this.$dbQuery(
"SELECT DISTINCT label FROM contact_labels ORDER BY label", "SELECT DISTINCT label FROM contact_labels ORDER BY label",
)) as QueryExecResult; )) as QueryExecResult;
return results.values?.map((r: SqlValue[]) => r[0] as string) || []; return results?.values?.map((r: SqlValue[]) => r[0] as string) || [];
} catch (error) { } catch (error) {
logger.error( logger.error(
"[PlatformServiceMixin] Error getting unique labels:", "[PlatformServiceMixin] Error getting unique labels:",