Skip to content

Commit ae1fbd4

Browse files
fix: handle missing ScanID and TaskID in AnalysisContext.AddFinding (#27)
Refactors AddFinding to populate missing ScanID and TaskID from the analysis context. Adds a defensive fallback to a Nil UUID if IDs are still missing, preventing "unable to encode empty string into binary format for uuid" errors during database persistence. Logs a warning when the fallback is used to aid in debugging. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 287d624 commit ae1fbd4

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

internal/analysis/core/context.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,31 @@ type AnalysisContext struct {
5151
// finding. It automatically populates the finding with the scan ID from the
5252
// current task context before appending it to the list of findings.
5353
func (ac *AnalysisContext) AddFinding(finding schemas.Finding) {
54-
if finding.ScanID == "" && ac.Task.ScanID != "" {
55-
finding.ScanID = ac.Task.ScanID
54+
// 1. Populate missing ScanID from Task context
55+
if finding.ScanID == "" {
56+
if ac.Task.ScanID != "" {
57+
finding.ScanID = ac.Task.ScanID
58+
} else {
59+
// Fallback: If no ScanID is available, use Nil UUID to avoid DB error "unable to encode empty string for uuid".
60+
finding.ScanID = "00000000-0000-0000-0000-000000000000"
61+
if ac.Logger != nil {
62+
ac.Logger.Warn("Finding reported without ScanID and no Task context available. Using Nil UUID.", zap.String("finding_id", finding.ID))
63+
}
64+
}
5665
}
66+
67+
// 2. Populate missing TaskID from Task context
68+
if finding.TaskID == "" {
69+
if ac.Task.TaskID != "" {
70+
finding.TaskID = ac.Task.TaskID
71+
} else {
72+
// Fallback: If no TaskID is available, use Nil UUID to avoid DB error.
73+
finding.TaskID = "00000000-0000-0000-0000-000000000000"
74+
if ac.Logger != nil {
75+
ac.Logger.Warn("Finding reported without TaskID and no Task context available. Using Nil UUID.", zap.String("finding_id", finding.ID))
76+
}
77+
}
78+
}
79+
5780
ac.Findings = append(ac.Findings, finding)
5881
}

0 commit comments

Comments
 (0)