From 01984331b7337492b833d6b96ddb020d56654e39 Mon Sep 17 00:00:00 2001 From: Parth Patel <88045217+pxp928@users.noreply.github.com> Date: Tue, 23 May 2023 14:39:55 -0400 Subject: [PATCH] fix logger error message output (#882) * replace w with v in logger message Signed-off-by: pxp928 * change between error message and logger Signed-off-by: pxp928 --------- Signed-off-by: pxp928 --- cmd/guacingest/cmd/ingest.go | 8 ++++---- cmd/guacone/cmd/files.go | 2 +- cmd/guacone/cmd/oci.go | 2 +- cmd/guacone/cmd/osv.go | 4 ++-- cmd/guacone/cmd/scorecard.go | 4 ++-- internal/testing/cmd/pubsub_test/cmd/osv.go | 2 +- pkg/certifier/certify/certify.go | 6 +++--- pkg/certifier/certify/certify_test.go | 12 ++++++------ pkg/emitter/nats_emitter.go | 8 ++++---- pkg/emitter/nats_emitter_test.go | 12 ++++++------ pkg/handler/collector/collector_test.go | 12 ++++++------ pkg/handler/collector/deps_dev/deps_dev.go | 6 +++--- pkg/handler/collector/github/github.go | 8 ++++---- pkg/handler/processor/process/process.go | 9 +++------ pkg/ingestor/parser/dsse/parser_dsse.go | 2 +- pkg/ingestor/parser/parser.go | 9 +++------ pkg/ingestor/parser/vuln/vuln.go | 2 +- .../verifier/sigstore_verifier/sigstore_verifier.go | 2 +- 18 files changed, 52 insertions(+), 58 deletions(-) diff --git a/cmd/guacingest/cmd/ingest.go b/cmd/guacingest/cmd/ingest.go index 173b198010..e572d385c2 100644 --- a/cmd/guacingest/cmd/ingest.go +++ b/cmd/guacingest/cmd/ingest.go @@ -67,7 +67,7 @@ func ingest(cmd *cobra.Command, args []string) { jetStream := emitter.NewJetStream(opts.natsAddr, "", "") ctx, err = jetStream.JetStreamInit(ctx) if err != nil { - logger.Errorf("jetStream initialization failed with error: %w", err) + logger.Errorf("jetStream initialization failed with error: %v", err) os.Exit(1) } defer jetStream.Close() @@ -75,7 +75,7 @@ func ingest(cmd *cobra.Command, args []string) { // initialize collectsub client csubClient, err := csub_client.NewClient(opts.csubAddr) if err != nil { - logger.Errorf("collectsub client initialization failed with error: %w", err) + logger.Errorf("collectsub client initialization failed with error: %v", err) os.Exit(1) } defer csubClient.Close() @@ -116,13 +116,13 @@ func ingest(cmd *cobra.Command, args []string) { processorFunc, err := getProcessor(ctx, processorTransportFunc) if err != nil { - logger.Errorf("error: %w", err) + logger.Errorf("error: %v", err) os.Exit(1) } ingestorFunc, err := getIngestor(ctx, ingestorTransportFunc) if err != nil { - logger.Errorf("error: %w", err) + logger.Errorf("error: %v", err) os.Exit(1) } diff --git a/cmd/guacone/cmd/files.go b/cmd/guacone/cmd/files.go index e09390be57..595a2e3e31 100644 --- a/cmd/guacone/cmd/files.go +++ b/cmd/guacone/cmd/files.go @@ -114,7 +114,7 @@ var filesCmd = &cobra.Command{ // initialize collectsub client csubClient, err := csub_client.NewClient(opts.csubAddr) if err != nil { - logger.Infof("collectsub client initialization failed, this ingestion will not pull in any additional data through the collectsub service: %w", err) + logger.Infof("collectsub client initialization failed, this ingestion will not pull in any additional data through the collectsub service: %v", err) csubClient = nil } else { defer csubClient.Close() diff --git a/cmd/guacone/cmd/oci.go b/cmd/guacone/cmd/oci.go index 4b64749611..4e8980d499 100644 --- a/cmd/guacone/cmd/oci.go +++ b/cmd/guacone/cmd/oci.go @@ -67,7 +67,7 @@ var ociCmd = &cobra.Command{ // initialize collectsub client csubClient, err := csub_client.NewClient(opts.csubAddr) if err != nil { - logger.Infof("collectsub client initialization failed, this ingestion will not pull in any additional data through the collectsub service: %w", err) + logger.Infof("collectsub client initialization failed, this ingestion will not pull in any additional data through the collectsub service: %v", err) csubClient = nil } else { defer csubClient.Close() diff --git a/cmd/guacone/cmd/osv.go b/cmd/guacone/cmd/osv.go index ea5c5912b8..caa998d981 100644 --- a/cmd/guacone/cmd/osv.go +++ b/cmd/guacone/cmd/osv.go @@ -65,13 +65,13 @@ var osvCmd = &cobra.Command{ } if err := certify.RegisterCertifier(osv.NewOSVCertificationParser, certifier.CertifierOSV); err != nil { - logger.Fatalf("unable to register certifier: %w", err) + logger.Fatalf("unable to register certifier: %v", err) } // initialize collectsub client csubClient, err := csub_client.NewClient(opts.csubAddr) if err != nil { - logger.Infof("collectsub client initialization failed, this ingestion will not pull in any additional data through the collectsub service: %w", err) + logger.Infof("collectsub client initialization failed, this ingestion will not pull in any additional data through the collectsub service: %v", err) csubClient = nil } else { defer csubClient.Close() diff --git a/cmd/guacone/cmd/scorecard.go b/cmd/guacone/cmd/scorecard.go index ed61b07872..f30c031b62 100644 --- a/cmd/guacone/cmd/scorecard.go +++ b/cmd/guacone/cmd/scorecard.go @@ -77,7 +77,7 @@ var scorecardCmd = &cobra.Command{ // initialize collectsub client csubClient, err := csub_client.NewClient(opts.csubAddr) if err != nil { - logger.Infof("collectsub client initialization failed, this ingestion will not pull in any additional data through the collectsub service: %w", err) + logger.Infof("collectsub client initialization failed, this ingestion will not pull in any additional data through the collectsub service: %v", err) csubClient = nil } else { defer csubClient.Close() @@ -109,7 +109,7 @@ var scorecardCmd = &cobra.Command{ scCertifier := func() certifier.Certifier { return scorecardCertifier } if err := certify.RegisterCertifier(scCertifier, certifier.CertifierScorecard); err != nil { - logger.Fatalf("unable to register certifier: %w", err) + logger.Fatalf("unable to register certifier: %v", err) } processorFunc := getProcessor(ctx) collectSubEmitFunc := getCollectSubEmit(ctx, csubClient) diff --git a/internal/testing/cmd/pubsub_test/cmd/osv.go b/internal/testing/cmd/pubsub_test/cmd/osv.go index f04cd1cfc9..ded80e3c9c 100644 --- a/internal/testing/cmd/pubsub_test/cmd/osv.go +++ b/internal/testing/cmd/pubsub_test/cmd/osv.go @@ -62,7 +62,7 @@ var osvCmd = &cobra.Command{ } if err := certify.RegisterCertifier(osv.NewOSVCertificationParser, certifier.CertifierOSV); err != nil { - logger.Fatalf("unable to register certifier: %w", err) + logger.Fatalf("unable to register certifier: %v", err) } // TODO: Fix this with the graphQL endpoint diff --git a/pkg/certifier/certify/certify.go b/pkg/certifier/certify/certify.go index 4d17128554..ee11ae2bf0 100644 --- a/pkg/certifier/certify/certify.go +++ b/pkg/certifier/certify/certify.go @@ -86,7 +86,7 @@ func Certify(ctx context.Context, query certifier.QueryComponents, emitter certi for len(compChan) > 0 { d := <-compChan if err := generateDocuments(ctx, d, emitter, handleErr); err != nil { - logger.Errorf("generate certifier documents error: %w", err) + logger.Errorf("generate certifier documents error: %v", err) } } return nil @@ -140,7 +140,7 @@ func generateDocuments(ctx context.Context, collectedComponent interface{}, emit select { case d := <-docChan: if err := emitter(d); err != nil { - logger.Errorf("emit error: %w", err) + logger.Errorf("emit error: %v", err) } case err := <-errChan: if !handleErr(err) { @@ -154,7 +154,7 @@ func generateDocuments(ctx context.Context, collectedComponent interface{}, emit for len(docChan) > 0 { d := <-docChan if err := emitter(d); err != nil { - logger.Errorf("emit error: %w", err) + logger.Errorf("emit error: %v", err) } } return nil diff --git a/pkg/certifier/certify/certify_test.go b/pkg/certifier/certify/certify_test.go index f632603524..c0c2437b66 100644 --- a/pkg/certifier/certify/certify_test.go +++ b/pkg/certifier/certify/certify_test.go @@ -279,9 +279,9 @@ func testSubscribe(ctx context.Context, transportFunc func(processor.DocumentTre doc := processor.Document{} err := json.Unmarshal(d, &doc) if err != nil { - fmtErr := fmt.Errorf("[processor: %s] failed unmarshal the document bytes: %w", uuidString, err) - logger.Error(fmtErr) - return fmtErr + fmtErrString := fmt.Sprintf("[processor: %s] failed unmarshal the document bytes", uuidString) + logger.Errorf(fmtErrString+": %v", err) + return fmt.Errorf(fmtErrString+": %w", err) } docNode := &processor.DocumentNode{ @@ -292,9 +292,9 @@ func testSubscribe(ctx context.Context, transportFunc func(processor.DocumentTre docTree := processor.DocumentTree(docNode) err = transportFunc(docTree) if err != nil { - fmtErr := fmt.Errorf("[processor: %s] failed transportFunc: %w", uuidString, err) - logger.Error(fmtErr) - return fmtErr + fmtErrString := fmt.Sprintf("[processor: %s] failed transportFunc", uuidString) + logger.Errorf(fmtErrString+": %v", err) + return fmt.Errorf(fmtErrString+": %w", err) } logger.Infof("[processor: %s] docTree Processed: %+v", uuidString, docTree.Document.SourceInformation) return nil diff --git a/pkg/emitter/nats_emitter.go b/pkg/emitter/nats_emitter.go index 8b9024a1f8..113f9e5609 100644 --- a/pkg/emitter/nats_emitter.go +++ b/pkg/emitter/nats_emitter.go @@ -178,7 +178,7 @@ func createSubscriber(ctx context.Context, id string, subj string, durable strin js := FromContext(ctx) sub, err := js.PullSubscribe(subj, durable) if err != nil { - logger.Errorf("%s subscribe failed: %w", durable, err) + logger.Errorf("%s subscribe failed: %v", durable, err) return nil, nil, err } go func() { @@ -207,9 +207,9 @@ func createSubscriber(ctx context.Context, id string, subj string, durable strin if len(msgs) > 0 { err := msgs[0].Ack() if err != nil { - fmtErr := fmt.Errorf("[%s: %v] unable to Ack: %w", durable, id, err) - logger.Error(fmtErr) - errChan <- fmtErr + fmtErrString := fmt.Sprintf("[%s: %v] unable to Ack", durable, id) + logger.Errorf(fmtErrString+": %v", err) + errChan <- fmt.Errorf(fmtErrString+": %w", err) return } dataChan <- msgs[0].Data diff --git a/pkg/emitter/nats_emitter_test.go b/pkg/emitter/nats_emitter_test.go index 5112ad35a6..70cfd7013e 100644 --- a/pkg/emitter/nats_emitter_test.go +++ b/pkg/emitter/nats_emitter_test.go @@ -275,9 +275,9 @@ func testSubscribe(ctx context.Context, transportFunc func(processor.DocumentTre doc := processor.Document{} err := json.Unmarshal(d, &doc) if err != nil { - fmtErr := fmt.Errorf("[processor: %s] failed unmarshal the document bytes: %w", uuidString, err) - logger.Error(fmtErr) - return fmtErr + fmtErrString := fmt.Sprintf("[processor: %s] failed unmarshal the document bytes", uuidString) + logger.Errorf(fmtErrString+": %v", err) + return fmt.Errorf(fmtErrString+": %w", err) } docNode := &processor.DocumentNode{ @@ -288,9 +288,9 @@ func testSubscribe(ctx context.Context, transportFunc func(processor.DocumentTre docTree := processor.DocumentTree(docNode) err = transportFunc(docTree) if err != nil { - fmtErr := fmt.Errorf("[processor: %s] failed transportFunc: %w", uuidString, err) - logger.Error(fmtErr) - return fmtErr + fmtErrString := fmt.Sprintf("[processor: %s] failed transportFunc", uuidString) + logger.Errorf(fmtErrString+": %v", err) + return fmt.Errorf(fmtErrString+": %w", err) } logger.Infof("[processor: %s] docTree Processed: %+v", uuidString, docTree.Document.SourceInformation) return nil diff --git a/pkg/handler/collector/collector_test.go b/pkg/handler/collector/collector_test.go index b6fd01232a..32541593d5 100644 --- a/pkg/handler/collector/collector_test.go +++ b/pkg/handler/collector/collector_test.go @@ -151,9 +151,9 @@ func testSubscribe(ctx context.Context, transportFunc func(processor.DocumentTre doc := processor.Document{} err := json.Unmarshal(d, &doc) if err != nil { - fmtErr := fmt.Errorf("[processor: %s] failed unmarshal the document bytes: %w", uuidString, err) - logger.Error(fmtErr) - return fmtErr + fmtErrString := fmt.Sprintf("[processor: %s] failed unmarshal the document bytes", uuidString) + logger.Errorf(fmtErrString+": %v", err) + return fmt.Errorf(fmtErrString+": %w", err) } docNode := &processor.DocumentNode{ @@ -164,9 +164,9 @@ func testSubscribe(ctx context.Context, transportFunc func(processor.DocumentTre docTree := processor.DocumentTree(docNode) err = transportFunc(docTree) if err != nil { - fmtErr := fmt.Errorf("[processor: %s] failed transportFunc: %w", uuidString, err) - logger.Error(fmtErr) - return fmtErr + fmtErrString := fmt.Sprintf("[processor: %s] failed transportFunc", uuidString) + logger.Errorf(fmtErrString+": %v", err) + return fmt.Errorf(fmtErrString+": %w", err) } logger.Infof("[processor: %s] docTree Processed: %+v", uuidString, docTree.Document.SourceInformation) return nil diff --git a/pkg/handler/collector/deps_dev/deps_dev.go b/pkg/handler/collector/deps_dev/deps_dev.go index 37b14714e9..72ee2d778f 100644 --- a/pkg/handler/collector/deps_dev/deps_dev.go +++ b/pkg/handler/collector/deps_dev/deps_dev.go @@ -158,14 +158,14 @@ func (d *depsCollector) fetchDependencies(ctx context.Context, purl string, docC err = d.collectAdditionalMetadata(ctx, packageInput.Type, packageInput.Namespace, packageInput.Name, packageInput.Version, component) if err != nil { - logger.Debugf("failed to get additional metadata for package: %s, err: %w", purl, err) + logger.Debugf("failed to get additional metadata for package: %s, err: %v", purl, err) } // Make an RPC Request. The returned result is a stream of // DependenciesResponse structs. versionKey, err := getVersionKey(packageInput.Type, packageInput.Namespace, packageInput.Name, packageInput.Version) if err != nil { - logger.Infof("failed to getVersionKey with the following error: %w", err) + logger.Infof("failed to getVersionKey with the following error: %v", err) return nil } @@ -217,7 +217,7 @@ func (d *depsCollector) fetchDependencies(ctx context.Context, purl string, docC depComponent.CurrentPackage = depPackageInput err = d.collectAdditionalMetadata(ctx, depPackageInput.Type, depPackageInput.Namespace, depPackageInput.Name, depPackageInput.Version, depComponent) if err != nil { - logger.Debugf("failed to get additional metadata for package: %s, err: %w", depPurl, err) + logger.Debugf("failed to get additional metadata for package: %s, err: %v", depPurl, err) } dependencyNodes = append(dependencyNodes, depComponent) d.checkedPurls[depPurl] = depComponent diff --git a/pkg/handler/collector/github/github.go b/pkg/handler/collector/github/github.go index a3975775dc..822402117b 100644 --- a/pkg/handler/collector/github/github.go +++ b/pkg/handler/collector/github/github.go @@ -159,7 +159,7 @@ func (g *githubCollector) populateRepoToReleaseTags(ctx context.Context) error { for _, grds := range ds.GithubReleaseDataSources { r, t, err := ParseGithubReleaseDataSource(grds) if err != nil { - logger.Warnf("unable to parse github datasource: %w", err) + logger.Warnf("unable to parse github datasource: %v", err) continue } g.repoToReleaseTags[*r] = append(g.repoToReleaseTags[*r], t) @@ -168,7 +168,7 @@ func (g *githubCollector) populateRepoToReleaseTags(ctx context.Context) error { for _, gds := range ds.GitDataSources { r, t, err := ParseGitDataSource(gds) if err != nil { - logger.Warnf("unable to parse git datasource: %w", err) + logger.Warnf("unable to parse git datasource: %v", err) } g.repoToReleaseTags[*r] = append(g.repoToReleaseTags[*r], t) } @@ -189,7 +189,7 @@ func (g *githubCollector) fetchAssets(ctx context.Context, owner string, repo st release, err = g.client.GetReleaseByTag(ctx, owner, repo, gitTag) } if err != nil { - logger.Warnf("unable to fetch release: %w", err) + logger.Warnf("unable to fetch release: %v", err) continue } releases = append(releases, *release) @@ -209,7 +209,7 @@ func (g *githubCollector) collectAssetsForRelease(ctx context.Context, release c if checkSuffixes(asset.URL, g.assetSuffixes) { content, err := g.client.GetReleaseAsset(asset) if err != nil { - logger.Warnf("unable to download asset: %w", err) + logger.Warnf("unable to download asset: %v", err) continue } doc := &processor.Document{ diff --git a/pkg/handler/processor/process/process.go b/pkg/handler/processor/process/process.go index 8fdad13ac6..f7330b4cb6 100644 --- a/pkg/handler/processor/process/process.go +++ b/pkg/handler/processor/process/process.go @@ -77,21 +77,18 @@ func Subscribe(ctx context.Context, transportFunc func(processor.DocumentTree) e doc := processor.Document{} err := json.Unmarshal(d, &doc) if err != nil { - fmtErr := fmt.Errorf("[processor: %s] failed unmarshal the document bytes: %w", uuidString, err) - logger.Error(fmtErr) + logger.Errorf("[processor: %s] failed unmarshal the document bytes: %v", uuidString, err) return nil } docTree, err := Process(ctx, &doc) if err != nil { - fmtErr := fmt.Errorf("[processor: %s] failed process document: %w", uuidString, err) - logger.Error(fmtErr) + logger.Error("[processor: %s] failed process document: %v", uuidString, err) return nil } err = transportFunc(docTree) if err != nil { - fmtErr := fmt.Errorf("[processor: %s] failed transportFunc: %w", uuidString, err) - logger.Error(fmtErr) + logger.Error("[processor: %s] failed transportFunc: %v", uuidString, err) return nil } diff --git a/pkg/ingestor/parser/dsse/parser_dsse.go b/pkg/ingestor/parser/dsse/parser_dsse.go index ea8453520c..2864cf4f82 100644 --- a/pkg/ingestor/parser/dsse/parser_dsse.go +++ b/pkg/ingestor/parser/dsse/parser_dsse.go @@ -67,7 +67,7 @@ func (d *dsseParser) getIdentity(ctx context.Context) error { _ = pemBytes } else { logger := logging.FromContext(ctx) - logger.Errorf("failed to verify DSSE with provided key: %w", i.ID) + logger.Errorf("failed to verify DSSE with provided key: %v", i.ID) } } */ logger := logging.FromContext(ctx) diff --git a/pkg/ingestor/parser/parser.go b/pkg/ingestor/parser/parser.go index 8872ad90a6..13cbe7127d 100644 --- a/pkg/ingestor/parser/parser.go +++ b/pkg/ingestor/parser/parser.go @@ -90,21 +90,18 @@ func Subscribe(ctx context.Context, transportFunc func([]assembler.IngestPredica docNode := processor.DocumentNode{} err := json.Unmarshal(d, &docNode) if err != nil { - fmtErr := fmt.Errorf("[ingestor: %s] failed unmarshal the document tree bytes: %w", uuidString, err) - logger.Error(fmtErr) + logger.Error("[ingestor: %s] failed unmarshal the document tree bytes: %v", uuidString, err) return nil } assemblerInputs, idStrings, err := ParseDocumentTree(ctx, processor.DocumentTree(&docNode)) if err != nil { - fmtErr := fmt.Errorf("[ingestor: %s] failed parse document: %w", uuidString, err) - logger.Error(fmtErr) + logger.Error("[ingestor: %s] failed parse document: %v", uuidString, err) return nil } err = transportFunc(assemblerInputs, idStrings) if err != nil { - fmtErr := fmt.Errorf("[ingestor: %s] failed transportFunc: %w", uuidString, err) - logger.Error(fmtErr) + logger.Error("[ingestor: %s] failed transportFunc: %v", uuidString, err) return nil } diff --git a/pkg/ingestor/parser/vuln/vuln.go b/pkg/ingestor/parser/vuln/vuln.go index 9f43710316..037da4d261 100644 --- a/pkg/ingestor/parser/vuln/vuln.go +++ b/pkg/ingestor/parser/vuln/vuln.go @@ -120,7 +120,7 @@ func parseVulns(ctx context.Context, s *attestation_vuln.VulnerabilityStatement) vs = append(vs, v) cve, ghsa, err := helpers.OSVToGHSACVE(id.VulnerabilityId) if err != nil { - logger.Debugf("osvID is not a CVE or GHSA: %w", err) + logger.Debugf("osvID is not a CVE or GHSA: %v", err) continue } iv := assembler.IsVulnIngest{ diff --git a/pkg/ingestor/verifier/sigstore_verifier/sigstore_verifier.go b/pkg/ingestor/verifier/sigstore_verifier/sigstore_verifier.go index 05331ca72a..94a3b37e01 100644 --- a/pkg/ingestor/verifier/sigstore_verifier/sigstore_verifier.go +++ b/pkg/ingestor/verifier/sigstore_verifier/sigstore_verifier.go @@ -65,7 +65,7 @@ func (d *sigstoreVerifier) Verify(ctx context.Context, payloadBytes []byte) ([]v if err != nil { // logging here as we don't want to fail but record that the signature check failed logger := logging.FromContext(ctx) - logger.Errorf("failed to verify signature with provided key: %w", key.Hash) + logger.Errorf("failed to verify signature with provided key: %v", key.Hash) } // if err (meaning that the keyID or the signature verification failed), verified is set to false foundIdentity.Verified = (err == nil)