Skip to content

Commit 3ad498e

Browse files
authored
Update 'failed to assign ID' error message to include path (#5391)
To help determine which advisories are failing to parse, which is currently omitted when this fails (example: https://github.com/pypa/advisory-database/actions/runs/26036795928/job/76537293443)
1 parent 77f0674 commit 3ad498e

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

vulnfeeds/cmd/ids/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func assignIDs(prefix, dir string, format fileFormat) error {
185185
logger.Info("Assigning IDs using detected maximums", slog.Any("counters", yearCounters))
186186
for _, path := range unassigned {
187187
if err := assignID(prefix, path, format, yearCounters, defaultYear); err != nil {
188-
return fmt.Errorf("failed to assign ID: %w", err)
188+
return fmt.Errorf("failed to assign ID for %s: %w", path, err)
189189
}
190190
}
191191

vulnfeeds/cmd/ids/main_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"os"
66
"path/filepath"
7+
"strings"
78
"testing"
89
)
910

@@ -101,3 +102,21 @@ func TestAssignIDs(t *testing.T) {
101102
})
102103
}
103104
}
105+
106+
func TestAssignIDsError(t *testing.T) {
107+
tmpDir := t.TempDir()
108+
invalidFile := filepath.Join(tmpDir, "OSV-0000-invalid.yaml")
109+
if err := os.WriteFile(invalidFile, []byte("invalid yaml content"), 0600); err != nil {
110+
t.Fatalf("failed to setup invalid vuln: %v", err)
111+
}
112+
113+
err := assignIDs("OSV", tmpDir, fileFormatYAML)
114+
if err == nil {
115+
t.Fatal("expected error but got nil")
116+
}
117+
118+
expectedErr := "failed to assign ID for " + invalidFile
119+
if !strings.Contains(err.Error(), expectedErr) {
120+
t.Errorf("Expected error message to contain %q, but got %q", expectedErr, err.Error())
121+
}
122+
}

0 commit comments

Comments
 (0)