Skip to content

Commit

Permalink
Replace fmt.Errorf with errors.Errorf
Browse files Browse the repository at this point in the history
Fixes #3449
  • Loading branch information
martinmr committed Jul 3, 2019
1 parent 43c8d38 commit e99e989
Show file tree
Hide file tree
Showing 50 changed files with 229 additions and 223 deletions.
5 changes: 2 additions & 3 deletions chunker/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"bytes"
"compress/gzip"
encjson "encoding/json"
"fmt"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -155,7 +154,7 @@ func (jsonChunker) Begin(r *bufio.Reader) error {
return err
}
if ch != '[' {
return fmt.Errorf("JSON file must contain array. Found: %v", ch)
return errors.Errorf("JSON file must contain array. Found: %v", ch)
}
return nil
}
Expand All @@ -178,7 +177,7 @@ func (jsonChunker) Chunk(r *bufio.Reader) (*bytes.Buffer, error) {
// Handle loading an empty JSON array ("[]") without error.
return nil, io.EOF
} else if ch != '{' {
return nil, fmt.Errorf("Expected JSON map start. Found: %v", string(ch))
return nil, errors.Errorf("Expected JSON map start. Found: %v", string(ch))
}
x.Check2(out.WriteRune(ch))

Expand Down
2 changes: 1 addition & 1 deletion chunker/json/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func Parse(b []byte, op int) ([]*api.NQuad, error) {
}

if len(list) == 0 && len(ms) == 0 {
return nil, fmt.Errorf("Couldn't parse json as a map or an array")
return nil, errors.Errorf("Couldn't parse json as a map or an array")
}

var idx int
Expand Down
14 changes: 7 additions & 7 deletions compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,26 +371,26 @@ func main() {

// Do some sanity checks.
if opts.NumZeros < 1 || opts.NumZeros > 99 {
fatal(fmt.Errorf("number of zeros must be 1-99"))
fatal(errors.Errorf("number of zeros must be 1-99"))
}
if opts.NumAlphas < 1 || opts.NumAlphas > 99 {
fatal(fmt.Errorf("number of alphas must be 1-99"))
fatal(errors.Errorf("number of alphas must be 1-99"))
}
if opts.NumReplicas%2 == 0 {
fatal(fmt.Errorf("number of replicas must be odd"))
fatal(errors.Errorf("number of replicas must be odd"))
}
if opts.LruSizeMB < 1024 {
fatal(fmt.Errorf("LRU cache size must be >= 1024 MB"))
fatal(errors.Errorf("LRU cache size must be >= 1024 MB"))
}
if opts.AclSecret != "" && !opts.Enterprise {
warning("adding --enterprise because it is required by ACL feature")
opts.Enterprise = true
}
if opts.DataVol && opts.DataDir != "" {
fatal(fmt.Errorf("only one of --data_vol and --data_dir may be used at a time"))
fatal(errors.Errorf("only one of --data_vol and --data_dir may be used at a time"))
}
if opts.UserOwnership && opts.DataDir == "" {
fatal(fmt.Errorf("--user option requires --data_dir=<path>"))
fatal(errors.Errorf("--user option requires --data_dir=<path>"))
}

services := make(map[string]service)
Expand Down Expand Up @@ -437,7 +437,7 @@ func main() {
_, _ = fmt.Fprintf(os.Stderr, "Writing file: %s\n", opts.OutFile)
err = ioutil.WriteFile(opts.OutFile, []byte(doc), 0644)
if err != nil {
fatal(fmt.Errorf("unable to write file: %v", err))
fatal(errors.Errorf("unable to write file: %v", err))
}
}
}
6 changes: 3 additions & 3 deletions conn/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package conn

import (
"context"
"fmt"
"sync"
"time"

Expand All @@ -27,16 +26,17 @@ import (
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/x"
"github.com/golang/glog"
"github.com/pkg/errors"
"go.opencensus.io/plugin/ocgrpc"

"google.golang.org/grpc"
)

var (
// ErrNoConnection indicates no connection exists to a node.
ErrNoConnection = fmt.Errorf("No connection exists")
ErrNoConnection = errors.Errorf("No connection exists")
// ErrUnhealthyConnection indicates the connection to a node is unhealthy.
ErrUnhealthyConnection = fmt.Errorf("Unhealthy connection")
ErrUnhealthyConnection = errors.Errorf("Unhealthy connection")
echoDuration = 500 * time.Millisecond
)

Expand Down
6 changes: 4 additions & 2 deletions contrib/embargo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"os/exec"
"strings"
"time"

"github.com/pkg/errors"
)

var ctxb = context.Background()
Expand Down Expand Up @@ -56,7 +58,7 @@ func increment(atLeast int, args string) error {
}
}
if ok < atLeast {
return fmt.Errorf("Increment with atLeast=%d failed. OK: %d", atLeast, ok)
return errors.Errorf("Increment with atLeast=%d failed. OK: %d", atLeast, ok)
}
dur := time.Since(start).Round(time.Millisecond)
fmt.Printf("\n[%v] ===> TIME taken to converge %d alphas: %s\n\n",
Expand All @@ -76,7 +78,7 @@ func getStatus(zero string) error {
output := out.String()
if strings.Contains(output, "errors") {
fmt.Printf("ERROR. Status at %s. Output:\n%s\n", zero, output)
return fmt.Errorf(output)
return errors.Errorf(output)
}
// var m map[string]interface{}
// if err := json.Unmarshal([]byte(output), &m); err != nil {
Expand Down
7 changes: 3 additions & 4 deletions dgraph/cmd/alpha/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"compress/gzip"
"context"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -106,7 +105,7 @@ func parseUint64(r *http.Request, name string) (uint64, error) {

uintVal, err := strconv.ParseUint(value, 0, 64)
if err != nil {
return 0, fmt.Errorf("Error: %+v while parsing %s as uint64", err, name)
return 0, errors.Errorf("Error: %+v while parsing %s as uint64", err, name)
}

return uintVal, nil
Expand All @@ -122,7 +121,7 @@ func parseBool(r *http.Request, name string) (bool, error) {

boolval, err := strconv.ParseBool(value)
if err != nil {
return false, fmt.Errorf("Error: %+v while parsing %s as bool", err, name)
return false, errors.Errorf("Error: %+v while parsing %s as bool", err, name)
}

return boolval, nil
Expand All @@ -138,7 +137,7 @@ func parseDuration(r *http.Request, name string) (time.Duration, error) {

durationValue, err := time.ParseDuration(value)
if err != nil {
return 0, fmt.Errorf("Error: %+v while parsing %s as time.Duration", err, name)
return 0, errors.Errorf("Error: %+v while parsing %s as time.Duration", err, name)
}

return durationValue, nil
Expand Down
10 changes: 5 additions & 5 deletions dgraph/cmd/alpha/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"compress/gzip"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
Expand All @@ -31,6 +30,7 @@ import (
"testing"
"time"

"github.com/pkg/errors"
"github.com/stretchr/testify/require"

"github.com/dgraph-io/dgraph/query"
Expand Down Expand Up @@ -97,7 +97,7 @@ func queryWithGz(queryText, contentType, debug, timeout string, gzReq, gzResp bo
return "", nil, err
}
if status := resp.StatusCode; status != http.StatusOK {
return "", nil, fmt.Errorf("Unexpected status code: %v", status)
return "", nil, errors.Errorf("Unexpected status code: %v", status)
}

defer resp.Body.Close()
Expand All @@ -110,7 +110,7 @@ func queryWithGz(queryText, contentType, debug, timeout string, gzReq, gzResp bo
}
defer rd.Close()
} else {
return "", resp, fmt.Errorf("Response not compressed")
return "", resp, errors.Errorf("Response not compressed")
}
}
body, err := ioutil.ReadAll(rd)
Expand Down Expand Up @@ -233,13 +233,13 @@ func runRequest(req *http.Request) (*x.QueryResWithData, []byte, error) {
return nil, nil, err
}
if status := resp.StatusCode; status != http.StatusOK {
return nil, nil, fmt.Errorf("Unexpected status code: %v", status)
return nil, nil, errors.Errorf("Unexpected status code: %v", status)
}

defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, nil, fmt.Errorf("unable to read from body: %v", err)
return nil, nil, errors.Errorf("unable to read from body: %v", err)
}

qr := new(x.QueryResWithData)
Expand Down
13 changes: 7 additions & 6 deletions dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/dgraph-io/dgraph/x"

"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/spf13/cast"
"github.com/spf13/cobra"
"go.opencensus.io/plugin/ocgrpc"
Expand Down Expand Up @@ -219,7 +220,7 @@ func getIPsFromString(str string) ([]x.IPRange, error) {
} else {
ipAddrs, err := net.LookupIP(s)
if err != nil {
return nil, fmt.Errorf("invalid IP address or hostname: %s", s)
return nil, errors.Errorf("invalid IP address or hostname: %s", s)
}

for _, addr := range ipAddrs {
Expand All @@ -230,7 +231,7 @@ func getIPsFromString(str string) ([]x.IPRange, error) {
// string is CIDR block like 192.168.0.0/16 or fd03:b188:0f3c:9ec4::/64
rangeLo, network, err := net.ParseCIDR(s)
if err != nil {
return nil, fmt.Errorf("invalid CIDR block: %s", s)
return nil, errors.Errorf("invalid CIDR block: %s", s)
}

addrLen, maskLen := len(rangeLo), len(network.Mask)
Expand All @@ -247,15 +248,15 @@ func getIPsFromString(str string) ([]x.IPRange, error) {
rangeLo := net.ParseIP(tuple[0])
rangeHi := net.ParseIP(tuple[1])
if rangeLo == nil {
return nil, fmt.Errorf("invalid IP address: %s", tuple[0])
return nil, errors.Errorf("invalid IP address: %s", tuple[0])
} else if rangeHi == nil {
return nil, fmt.Errorf("invalid IP address: %s", tuple[1])
return nil, errors.Errorf("invalid IP address: %s", tuple[1])
} else if bytes.Compare(rangeLo, rangeHi) > 0 {
return nil, fmt.Errorf("inverted IP address range: %s", s)
return nil, errors.Errorf("inverted IP address range: %s", s)
}
ipRanges = append(ipRanges, x.IPRange{Lower: rangeLo, Upper: rangeHi})
default:
return nil, fmt.Errorf("invalid IP address range: %s", s)
return nil, errors.Errorf("invalid IP address range: %s", s)
}
}

Expand Down
3 changes: 2 additions & 1 deletion dgraph/cmd/alpha/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/dgraph-io/dgraph/schema"
"github.com/dgraph-io/dgraph/x"
"github.com/dgraph-io/dgraph/z"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
Expand Down Expand Up @@ -144,7 +145,7 @@ func runJSONMutation(m string) error {
func alterSchema(s string) error {
_, _, err := runWithRetries("PUT", "", addr+"/alter", s)
if err != nil {
return fmt.Errorf("error while running request with retries: %v", err)
return errors.Errorf("error while running request with retries: %v", err)
}
return nil
}
Expand Down
7 changes: 4 additions & 3 deletions dgraph/cmd/cert/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import (
"crypto/x509/pkix"
"encoding/hex"
"encoding/pem"
"fmt"
"math"
"math/big"
"net"
"os"
"time"

"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -109,7 +110,7 @@ func (c *certConfig) generatePair(keyFile, certFile string) error {
if c.parent == nil {
c.parent = template
} else if template.NotAfter.After(c.parent.NotAfter) {
return fmt.Errorf("--duration: certificate expiration date '%s' exceeds parent '%s'",
return errors.Errorf("--duration: certificate expiration date '%s' exceeds parent '%s'",
template.NotAfter, c.parent.NotAfter)
}

Expand Down Expand Up @@ -173,7 +174,7 @@ func (c *certConfig) verifyCert(certFile string) error {

_, err = cert.Verify(opts)
if err != nil {
return fmt.Errorf("%s: verification failed: %s", certFile, err)
return errors.Errorf("%s: verification failed: %s", certFile, err)
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions dgraph/cmd/cert/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ func readKey(keyFile string) (crypto.PrivateKey, error) {
block, _ := pem.Decode(b)
switch {
case block == nil:
return nil, fmt.Errorf("Failed to read key block")
return nil, errors.Errorf("Failed to read key block")
case block.Type == "EC PRIVATE KEY":
return x509.ParseECPrivateKey(block.Bytes)
case block.Type == "RSA PRIVATE KEY":
return x509.ParsePKCS1PrivateKey(block.Bytes)
}
return nil, fmt.Errorf("Unknown PEM type: %s", block.Type)
return nil, errors.Errorf("Unknown PEM type: %s", block.Type)
}

// readCert tries to read and decode the contents of a signed cert file.
Expand All @@ -129,9 +129,9 @@ func readCert(certFile string) (*x509.Certificate, error) {
block, _ := pem.Decode(b)
switch {
case block == nil:
return nil, fmt.Errorf("Failed to read cert block")
return nil, errors.Errorf("Failed to read cert block")
case block.Type != "CERTIFICATE":
return nil, fmt.Errorf("Unknown PEM type: %s", block.Type)
return nil, errors.Errorf("Unknown PEM type: %s", block.Type)
}

return x509.ParseCertificate(block.Bytes)
Expand Down
8 changes: 4 additions & 4 deletions dgraph/cmd/cert/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func getFileInfo(file string) *certInfo {
dnCommonNamePrefix, cert.Subject.CommonName)

default:
info.err = fmt.Errorf("Unsupported certificate")
info.err = errors.Errorf("Unsupported certificate")
return &info
}

Expand All @@ -91,7 +91,7 @@ func getFileInfo(file string) *certInfo {
if file != defaultCACert {
parent, err := readCert(defaultCACert)
if err != nil {
info.err = fmt.Errorf("Could not read parent cert: %s", err)
info.err = errors.Errorf("Could not read parent cert: %s", err)
return &info
}
if err := cert.CheckSignatureFrom(parent); err != nil {
Expand All @@ -112,7 +112,7 @@ func getFileInfo(file string) *certInfo {
info.commonName = dnCommonNamePrefix + " Client key"

default:
info.err = fmt.Errorf("Unsupported key")
info.err = errors.Errorf("Unsupported key")
return &info
}

Expand All @@ -136,7 +136,7 @@ func getFileInfo(file string) *certInfo {
}

default:
info.err = fmt.Errorf("Unsupported file")
info.err = errors.Errorf("Unsupported file")
}

return &info
Expand Down
3 changes: 2 additions & 1 deletion dgraph/cmd/counter/increment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/dgraph-io/dgo"
"github.com/dgraph-io/dgo/protos/api"
"github.com/dgraph-io/dgraph/x"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -80,7 +81,7 @@ func queryCounter(txn *dgo.Txn, pred string) (Counter, error) {
query := fmt.Sprintf("{ q(func: has(%s)) { uid, val: %s }}", pred, pred)
resp, err := txn.Query(ctx, query)
if err != nil {
return counter, fmt.Errorf("Query error: %v", err)
return counter, errors.Errorf("Query error: %v", err)
}

// Total query latency is sum of encoding, parsing and processing latencies.
Expand Down
Loading

0 comments on commit e99e989

Please sign in to comment.