Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golangci-lint: add nilerr & misc error reporting improvements #5742

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ linters:
- gosec
- misspell
- nakedret
- nilerr
- unconvert
- unparam
- whitespace
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/container/process/winapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (a *api) QuerySystemExtendedHandleInformation() ([]SystemHandleInformationE
handlesList := (*SystemExtendedHandleInformation)(unsafe.Pointer(&buffer[0]))
handles := unsafe.Slice(&handlesList.Handles[0], int(handlesList.NumberOfHandles))

return handles, nil
return handles, nil //nolint:nilerr
}

return nil, status
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/plugin/facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (f *Facade) InitLog(log logrus.FieldLogger) {
// that come out of plugin implementations.
func (f *Facade) WrapErr(err error) error {
if err == nil {
return err
return nil
}

// Embellish the gRPC status with the prefix, if necessary.
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/telemetry/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func newStatsdRunner(c *MetricsConfig) (sinkRunner, error) {
for _, sc := range c.FileConfig.Statsd {
sink, err := metrics.NewStatsdSink(sc.Address)
if err != nil {
return runner, nil
return nil, err
}

runner.loadedSinks = append(runner.loadedSinks, sink)
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/plugin/keymanager/awskms/awskms.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ func (p *Plugin) createDefaultPolicy(ctx context.Context) (*string, error) {
roleName, err := roleNameFromARN(*result.Arn)
if err != nil {
// the server has not assumed any role, use default KMS policy and log a warn message
p.log.Warn("In a future version of SPIRE, it will be mandatory for the SPIRE servers to assume an AWS IAM Role when using the default AWS KMS key policy. Please assign an IAM role to this SPIRE Server instance.")
p.log.Warn("In a future version of SPIRE, it will be mandatory for the SPIRE servers to assume an AWS IAM Role when using the default AWS KMS key policy. Please assign an IAM role to this SPIRE Server instance.", reasonTag, err)
return nil, nil
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/server/plugin/keymanager/awskms/awskms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ func TestGenerateKey(t *testing.T) {
{
Level: logrus.WarnLevel,
Message: "In a future version of SPIRE, it will be mandatory for the SPIRE servers to assume an AWS IAM Role when using the default AWS KMS key policy. Please assign an IAM role to this SPIRE Server instance.",
Data: logrus.Fields{reasonTag: `incomplete resource, expected 'resource-type/resource-id' but got "example-account-id"`},
},
},
},
Expand All @@ -734,6 +735,7 @@ func TestGenerateKey(t *testing.T) {
{
Level: logrus.WarnLevel,
Message: "In a future version of SPIRE, it will be mandatory for the SPIRE servers to assume an AWS IAM Role when using the default AWS KMS key policy. Please assign an IAM role to this SPIRE Server instance.",
Data: logrus.Fields{reasonTag: `arn does not contain an assumed role: "arn:aws:sts::example-account-id:user/development"`},
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func (s *Server) CheckHealth() health.State {
func (s *Server) tryGetBundle() error {
client, err := server_util.NewServerClient(s.config.BindLocalAddress)
if err != nil {
return errors.New("cannot create registration client")
return fmt.Errorf("cannot create registration client: %w", err)
}
defer client.Release()

Expand All @@ -531,7 +531,7 @@ func (s *Server) tryGetBundle() error {
// As currently coded however, the API isn't served until after
// the server CA has been signed by upstream.
if _, err := bundleClient.GetBundle(context.Background(), &bundlev1.GetBundleRequest{}); err != nil {
return errors.New("unable to fetch bundle")
return fmt.Errorf("unable to fetch bundle: %w", err)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/setup/node-attestation/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func doX509popStep(ctx context.Context) error {

// Ban agent
if err := banAgent(ctx, client, svidResp.Id); err != nil {
return errors.New("failed to ban agent")
return fmt.Errorf("failed to ban agent: %w", err)
}

// Reattest banned agent, it MUST fail
Expand Down
Loading