Skip to content

Commit

Permalink
fix logger error message output (#882)
Browse files Browse the repository at this point in the history
* replace w with v in logger message

Signed-off-by: pxp928 <parth.psu@gmail.com>

* change between error message and logger

Signed-off-by: pxp928 <parth.psu@gmail.com>

---------

Signed-off-by: pxp928 <parth.psu@gmail.com>
  • Loading branch information
pxp928 committed May 23, 2023
1 parent b696c10 commit 0198433
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 58 deletions.
8 changes: 4 additions & 4 deletions cmd/guacingest/cmd/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ 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()

// 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()
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/guacone/cmd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion cmd/guacone/cmd/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions cmd/guacone/cmd/osv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions cmd/guacone/cmd/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/testing/cmd/pubsub_test/cmd/osv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/certifier/certify/certify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pkg/certifier/certify/certify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/emitter/nats_emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pkg/emitter/nats_emitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pkg/handler/collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/handler/collector/deps_dev/deps_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/handler/collector/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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{
Expand Down
9 changes: 3 additions & 6 deletions pkg/handler/processor/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ingestor/parser/dsse/parser_dsse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions pkg/ingestor/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ingestor/parser/vuln/vuln.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0198433

Please sign in to comment.