Skip to content

Commit

Permalink
fix: remove duplicate logging
Browse files Browse the repository at this point in the history
Errors are now wrapped and returned to the caller, rather than logged
and returned to the caller.

Propagating the error to the caller causes errors to logged by the
`main` function (if they're propagated that far). Logging them elsewhere
results in the error being logged more than once.
  • Loading branch information
ctgardner committed Dec 18, 2024
1 parent 0b1eece commit 907c329
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/plugin/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plugin

import (
"context"
"fmt"

"github.com/cultureamp/example-go-buildkite-plugin/buildkite"
)
Expand All @@ -21,17 +22,15 @@ func (ep ExamplePlugin) Run(ctx context.Context, fetcher ConfigFetcher, agent Ag
var config Config
err := fetcher.Fetch(&config)
if err != nil {
buildkite.LogFailuref("plugin configuration error: %s\n", err.Error())
return err
return fmt.Errorf("plugin configuration error: %w", err)
}
annotation := config.Message

buildkite.Logf("Annotating with message: %s\n", annotation)

err = agent.Annotate(ctx, annotation, "info", "message")
if err != nil {
buildkite.LogFailuref("buildkite annotation error: %s\n", err.Error())
return err
return fmt.Errorf("buildkite annotation error: %w", err)
}

buildkite.Log("done.")
Expand Down

0 comments on commit 907c329

Please sign in to comment.