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

Enable error linting in code base #1428

Merged
merged 1 commit into from
Nov 23, 2022
Merged
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
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