Skip to content

Commit

Permalink
do not warn if DB missing (#2341)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
  • Loading branch information
wagoodman authored Dec 18, 2024
1 parent f263234 commit d94e68a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion grype/db/v6/description.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 6 additions & 1 deletion grype/db/v6/installation/curator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package installation

import (
"errors"
"fmt"
"os"
"path"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d94e68a

Please sign in to comment.