Skip to content

Commit

Permalink
Enable error linting in code base
Browse files Browse the repository at this point in the history
  • Loading branch information
johscheuer committed Nov 9, 2022
1 parent 9bdfd2e commit 418e820
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ linters:
- depguard
- dogsled
- errcheck
# - errorlint
- errorlint
- exportloopref
# - goconst
# - gocritic
Expand Down
8 changes: 5 additions & 3 deletions fdbclient/admin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package fdbclient
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -217,8 +218,8 @@ func (client *cliAdminClient) runCommand(command cliCommand) (string, error) {

output, err := execCommand.CombinedOutput()
if err != nil {
exitError, canCast := err.(*exec.ExitError)
if canCast {
var exitError *exec.ExitError
if errors.As(err, &exitError) {
client.log.Error(exitError, "Error from FDB command", "namespace", client.Cluster.Namespace, "cluster", client.Cluster.Name, "code", exitError.ProcessState.ExitCode(), "stdout", string(output), "stderr", string(exitError.Stderr))
}

Expand Down Expand Up @@ -263,7 +264,8 @@ func (client *cliAdminClient) runCommandWithBackoff(command string) (string, err
break
}

if _, ok := err.(fdbv1beta2.TimeoutError); ok {
var timoutError *fdbv1beta2.TimeoutError
if errors.As(err, &timoutError) {
client.log.Info("timeout issue will retry with higher timeout")
currentTimeout *= 2
continue
Expand Down
4 changes: 3 additions & 1 deletion fdbclient/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package fdbclient

import (
"errors"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -102,7 +103,8 @@ func getValueFromDBUsingKey(cluster *fdbv1beta2.FoundationDBCluster, log logr.Lo
})

if err != nil {
if fdbError, ok := err.(fdb.Error); ok {
var fdbError *fdb.Error
if errors.As(err, &fdbError) {
// See: https://apple.github.io/foundationdb/api-error-codes.html
// 1031: Operation aborted because the transaction timed out
if fdbError.Code == 1031 {
Expand Down
22 changes: 4 additions & 18 deletions internal/error_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,14 @@ import (

// IsNetworkError returns true if the network is a network error net.Error
func IsNetworkError(err error) bool {
for err != nil {
if _, ok := err.(net.Error); ok {
return true
}

err = errors.Unwrap(err)
}

return false
var netError net.Error
return errors.As(err, &netError)
}

// IsTimeoutError returns true if the observed error was a timeout error
func IsTimeoutError(err error) bool {
for err != nil {
if _, ok := err.(fdbv1beta2.TimeoutError); ok {
return true
}

err = errors.Unwrap(err)
}

return false
var timeoutError fdbv1beta2.TimeoutError
return errors.As(err, &timeoutError)
}

// IsQuotaExceeded returns true if the error returned by the Kubernetes API is a forbidden error with the error message
Expand Down
7 changes: 4 additions & 3 deletions internal/pod_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
package internal

import (
"net/http"
"net/url"
"time"

fdbv1beta2 "github.com/FoundationDB/fdb-kubernetes-operator/api/v1beta2"
"github.com/hashicorp/go-retryablehttp"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"net/http"
"net/url"
"time"
)

var _ = Describe("pod_client", func() {
Expand Down

0 comments on commit 418e820

Please sign in to comment.