Skip to content

Commit 60f4c68

Browse files
joanagmaiaclaude
andcommitted
fix: throw actionable errors on missing privateer output and DB lookups (IN-1170)
Addresses PR review: guard against null returns from redis cache and post-insert DB lookups so workflow failures surface with context instead of TypeError on undefined property access. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
1 parent 5e86ef1 commit 60f4c68

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

  • services/apps/security_best_practices_worker/src/activities

services/apps/security_best_practices_worker/src/activities/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,18 @@ export async function saveOSPSBaselineInsightsToDB(
9696
const CATALOG_ID = 'osps-baseline-2026-02'
9797
const redisCache = new RedisCache(`osps-baseline-insights`, svc.redis, svc.log)
9898
const result = await redisCache.get(key)
99+
if (!result) {
100+
throw new Error(`No cached privateer result found for key: ${key}`)
101+
}
99102
const parsedResult: ISecurityInsightsPrivateerResult = JSON.parse(result)
100-
const evaluationSuite = parsedResult['evaluation-suites'].find(
103+
const evaluationSuite = parsedResult['evaluation-suites']?.find(
101104
(s) => s['catalog-id'] === CATALOG_ID,
102105
)
106+
if (!evaluationSuite) {
107+
throw new Error(
108+
`No evaluation suite found for catalog '${CATALOG_ID}' in privateer output for repo ${repo.repoUrl}`,
109+
)
110+
}
103111

104112
const qx = pgpQx(svc.postgres.writer.connection())
105113

@@ -114,6 +122,11 @@ export async function saveOSPSBaselineInsightsToDB(
114122
})
115123

116124
const suite = await findEvaluationSuite(qx, repo.repoUrl, evaluationSuite['catalog-id'])
125+
if (!suite) {
126+
throw new Error(
127+
`Evaluation suite not found after insert for repo ${repo.repoUrl}, catalog ${evaluationSuite['catalog-id']}`,
128+
)
129+
}
117130

118131
for (const evaluation of evaluationSuite['control-evaluations'].evaluations) {
119132
const controlId = evaluation.control['entry-id']
@@ -131,6 +144,11 @@ export async function saveOSPSBaselineInsightsToDB(
131144
})
132145

133146
const controlEvaluation = await findSuiteControlEvaluation(qx, repo.repoUrl, controlId, suite.id)
147+
if (!controlEvaluation) {
148+
throw new Error(
149+
`Control evaluation not found after insert for repo ${repo.repoUrl}, controlId ${controlId}, suiteId ${suite.id}`,
150+
)
151+
}
134152
for (const assessment of evaluation['assessment-logs']) {
135153
const runDuration = assessment.end
136154
? `${new Date(assessment.end).getTime() - new Date(assessment.start).getTime()}ms`

0 commit comments

Comments
 (0)