diff --git a/grype/db/v6/description.go b/grype/db/v6/description.go index d3ad18f1db9..a1a35003ea3 100644 --- a/grype/db/v6/description.go +++ b/grype/db/v6/description.go @@ -18,6 +18,8 @@ import ( "github.com/anchore/grype/internal/schemaver" ) +var ErrDBDoesNotExist = errors.New("database does not exist") + const ChecksumFileName = VulnerabilityDBFileName + ".checksum" type Description struct { @@ -70,7 +72,7 @@ func ReadDescription(dbFilePath string) (*Description, error) { // check if exists if _, err := os.Stat(dbFilePath); err != nil { if errors.Is(err, os.ErrNotExist) { - return nil, fmt.Errorf("database does not exist") + return nil, ErrDBDoesNotExist } return nil, fmt.Errorf("failed to access database file: %w", err) } diff --git a/grype/db/v6/installation/curator.go b/grype/db/v6/installation/curator.go index bc38e729d08..7557e1978ee 100644 --- a/grype/db/v6/installation/curator.go +++ b/grype/db/v6/installation/curator.go @@ -1,6 +1,7 @@ package installation import ( + "errors" "fmt" "os" "path" @@ -131,7 +132,11 @@ func (c curator) Delete() error { func (c curator) Update() (bool, error) { current, err := db.ReadDescription(c.config.DBFilePath()) if err != nil { - log.WithFields("error", err).Warn("unable to read current database metadata (continuing with update)") + // we should not warn if the DB does not exist, as this is a common first-run case... but other cases we + // may care about, so warn in those cases. + if !errors.Is(err, db.ErrDBDoesNotExist) { + log.WithFields("error", err).Warn("unable to read current database metadata (continuing with update)") + } // downstream any non-existent DB should always be replaced with any best-candidate found current = nil } else {