Enforce log.WithError(err) static analysis and fix all violations (#11163)

* Use log.WithError static analysis from #11143 and fix all violations

* Fix another log violation after pulling from develop

* Update beacon-chain/sync/pending_blocks_queue.go

Co-authored-by: Potuz <potuz@prysmaticlabs.com>

* @potuz feedback

* Copy paste fail

* fix tests

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Potuz <potuz@prysmaticlabs.com>
This commit is contained in:
Preston Van Loon
2022-08-05 05:52:02 -05:00
committed by GitHub
parent 1323912625
commit 9d375969d1
61 changed files with 193 additions and 175 deletions

View File

@@ -87,7 +87,7 @@ func main() {
// check if the database file is present.
dbNameWithPath := filepath.Join(*datadir, *dbName)
if _, err := os.Stat(dbNameWithPath); os.IsNotExist(err) {
log.Fatalf("could not locate database file : %s, %v", dbNameWithPath, err)
log.WithError(err).WithField("path", dbNameWithPath).Fatal("could not locate database file")
}
switch *command {
@@ -104,7 +104,7 @@ func main() {
case "migration-check":
destDbNameWithPath := filepath.Join(*destDatadir, *dbName)
if _, err := os.Stat(destDbNameWithPath); os.IsNotExist(err) {
log.Fatalf("could not locate destination database file : %s, %v", destDbNameWithPath, err)
log.WithError(err).WithField("path", destDbNameWithPath).Fatal("could not locate database file")
}
switch *migrationName {
case "validator-entries":
@@ -133,14 +133,14 @@ func printBucketContents(dbNameWithPath string, rowLimit uint64, bucketName stri
dbDirectory := filepath.Dir(dbNameWithPath)
db, openErr := kv.NewKVStore(context.Background(), dbDirectory, &kv.Config{})
if openErr != nil {
log.Fatalf("could not open db, %v", openErr)
log.WithError(openErr).Fatal("could not open db")
}
// don't forget to close it when ejecting out of this function.
defer func() {
closeErr := db.Close()
if closeErr != nil {
log.Fatalf("could not close db, %v", closeErr)
log.WithError(closeErr).Fatal("could not close db")
}
}()
@@ -166,14 +166,14 @@ func readBucketStat(dbNameWithPath string, statsC chan<- *bucketStat) {
// open the raw database file. If the file is busy, then exit.
db, openErr := bolt.Open(dbNameWithPath, 0600, &bolt.Options{Timeout: 1 * time.Second})
if openErr != nil {
log.Fatalf("could not open db to show bucket stats, %v", openErr)
log.WithError(openErr).Fatal("could not open db to show bucket stats")
}
// make sure we close the database before ejecting out of this function.
defer func() {
closeErr := db.Close()
if closeErr != nil {
log.Fatalf("could not close db after showing bucket stats, %v", closeErr)
log.WithError(closeErr).Fatalf("could not close db after showing bucket stats")
}
}()
@@ -185,7 +185,7 @@ func readBucketStat(dbNameWithPath string, statsC chan<- *bucketStat) {
return nil
})
}); viewErr1 != nil {
log.Fatalf("could not read buckets from db while getting list of buckets: %v", viewErr1)
log.WithError(viewErr1).Fatal("could not read buckets from db while getting list of buckets")
}
// for every bucket, calculate the stats and send it for printing.
@@ -381,7 +381,7 @@ func checkValidatorMigration(dbNameWithPath, destDbNameWithPath string) {
sourceDbDirectory := filepath.Dir(dbNameWithPath)
sourceDB, openErr := kv.NewKVStore(context.Background(), sourceDbDirectory, &kv.Config{})
if openErr != nil {
log.Fatalf("could not open sourceDB: %v", openErr)
log.WithError(openErr).Fatal("could not open sourceDB")
}
destinationDbDirectory := filepath.Dir(destDbNameWithPath)
@@ -391,7 +391,7 @@ func checkValidatorMigration(dbNameWithPath, destDbNameWithPath string) {
// if you want to avoid this then we should pass the metric name when opening the DB which touches
// too many places.
if openErr.Error() != "duplicate metrics collector registration attempted" {
log.Fatalf("could not open sourceDB, %v", openErr)
log.WithError(openErr).Fatalf("could not open sourceDB")
}
}
@@ -399,13 +399,13 @@ func checkValidatorMigration(dbNameWithPath, destDbNameWithPath string) {
defer func() {
closeErr := sourceDB.Close()
if closeErr != nil {
log.Fatalf("could not close sourceDB: %v", closeErr)
log.WithError(closeErr).Fatal("could not close sourceDB")
}
}()
defer func() {
closeErr := destDB.Close()
if closeErr != nil {
log.Fatalf("could not close sourceDB: %v", closeErr)
log.WithError(closeErr).Fatal("could not close sourceDB")
}
}()
@@ -414,11 +414,11 @@ func checkValidatorMigration(dbNameWithPath, destDbNameWithPath string) {
for rowCount, key := range sourceStateKeys[910:] {
sourceState, stateErr := sourceDB.State(ctx, bytesutil.ToBytes32(key))
if stateErr != nil {
log.Fatalf("could not get from source db, the state for key : %s, %v", hexutils.BytesToHex(key), stateErr)
log.WithError(stateErr).WithField("key", hexutils.BytesToHex(key)).Fatalf("could not get from source db, the state for key")
}
destinationState, stateErr := destDB.State(ctx, bytesutil.ToBytes32(key))
if stateErr != nil {
log.Fatalf("could not get destination db, the state for key : %s, %v", hexutils.BytesToHex(key), stateErr)
log.WithError(stateErr).WithField("key", hexutils.BytesToHex(key)).Fatalf("could not get from destination db, the state for key")
}
if destinationState == nil {
log.Infof("could not find state in migrated DB: index = %d, slot = %d, epoch = %d, numOfValidators = %d, key = %s",
@@ -432,13 +432,13 @@ func checkValidatorMigration(dbNameWithPath, destDbNameWithPath string) {
}
sourceStateHash, err := sourceState.HashTreeRoot(ctx)
if err != nil {
log.Fatalf("could not find hash of source state: %v", err)
log.WithError(err).Fatal("could not find hash of source state")
}
destinationSatteHash, err := destinationState.HashTreeRoot(ctx)
destinationStateHash, err := destinationState.HashTreeRoot(ctx)
if err != nil {
log.Fatalf("could not find hash of destination state: %v", err)
log.WithError(err).Fatal("could not find hash of destination state")
}
if !bytes.Equal(sourceStateHash[:], destinationSatteHash[:]) {
if !bytes.Equal(sourceStateHash[:], destinationStateHash[:]) {
log.Fatalf("state mismatch : key = %s", hexutils.BytesToHex(key))
}
}
@@ -449,14 +449,14 @@ func keysOfBucket(dbNameWithPath string, bucketName []byte, rowLimit uint64) ([]
// open the raw database file. If the file is busy, then exit.
db, openErr := bolt.Open(dbNameWithPath, 0600, &bolt.Options{Timeout: 1 * time.Second})
if openErr != nil {
log.Fatalf("could not open db while getting keys of a bucket, %v", openErr)
log.WithError(openErr).Fatal("could not open db while getting keys of a bucket")
}
// make sure we close the database before ejecting out of this function.
defer func() {
closeErr := db.Close()
if closeErr != nil {
log.Fatalf("could not close db while getting keys of a bucket, %v", closeErr)
log.WithError(closeErr).Fatal("could not close db while getting keys of a bucket")
}
}()
@@ -481,7 +481,7 @@ func keysOfBucket(dbNameWithPath string, bucketName []byte, rowLimit uint64) ([]
}
return nil
}); viewErr != nil {
log.Fatalf("could not read keys of bucket from db: %v", viewErr)
log.WithError(viewErr).Fatal("could not read keys of bucket from db")
}
return keys, sizes
}