mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-30 19:55:42 +00:00
change use of errors.Wrap to fmt.Errorf with %w verb
Closes #4603 Commands used (VIM): ``` :args `rg -l errors.Wrap` :argdo normal @q | update ``` where q is a macros rewriting the `errors.Wrap` to `fmt.Errorf`.
This commit is contained in:
+2
-3
@@ -1,9 +1,8 @@
|
||||
package async
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
//----------------------------------------
|
||||
@@ -144,7 +143,7 @@ func Parallel(tasks ...Task) (trs *TaskResultSet, ok bool) {
|
||||
if pnk := recover(); pnk != nil {
|
||||
atomic.AddInt32(numPanics, 1)
|
||||
// Send panic to taskResultCh.
|
||||
taskResultCh <- TaskResult{nil, errors.Errorf("panic in task %v", pnk)}
|
||||
taskResultCh <- TaskResult{nil, fmt.Errorf("panic in task %v", pnk)}
|
||||
// Closing taskResultCh lets trs.Wait() work.
|
||||
close(taskResultCh)
|
||||
// Decrement waitgroup.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package async
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -125,7 +125,7 @@ func TestParallelRecover(t *testing.T) {
|
||||
// Verify task #0, #1, #2.
|
||||
checkResult(t, taskResultSet, 0, 0, nil, nil)
|
||||
checkResult(t, taskResultSet, 1, 1, errors.New("some error"), nil)
|
||||
checkResult(t, taskResultSet, 2, nil, nil, errors.Errorf("panic in task %v", 2).Error())
|
||||
checkResult(t, taskResultSet, 2, nil, nil, fmt.Errorf("panic in task %v", 2).Error())
|
||||
}
|
||||
|
||||
// Wait for result
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package bech32
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/btcsuite/btcutil/bech32"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
//ConvertAndEncode converts from a base64 encoded byte string to base32 encoded byte string and then to bech32
|
||||
func ConvertAndEncode(hrp string, data []byte) (string, error) {
|
||||
converted, err := bech32.ConvertBits(data, 8, 5, true)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "encoding bech32 failed")
|
||||
return "", fmt.Errorf("encoding bech32 failed: %w", err)
|
||||
}
|
||||
return bech32.Encode(hrp, converted)
|
||||
|
||||
@@ -19,11 +20,11 @@ func ConvertAndEncode(hrp string, data []byte) (string, error) {
|
||||
func DecodeAndConvert(bech string) (string, []byte, error) {
|
||||
hrp, data, err := bech32.Decode(bech)
|
||||
if err != nil {
|
||||
return "", nil, errors.Wrap(err, "decoding bech32 failed")
|
||||
return "", nil, fmt.Errorf("decoding bech32 failed: %w", err)
|
||||
}
|
||||
converted, err := bech32.ConvertBits(data, 5, 8, false)
|
||||
if err != nil {
|
||||
return "", nil, errors.Wrap(err, "decoding bech32 failed")
|
||||
return "", nil, fmt.Errorf("decoding bech32 failed: %w", err)
|
||||
}
|
||||
return hrp, converted, nil
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
)
|
||||
|
||||
@@ -51,7 +50,7 @@ func ParseLogLevel(lvl string, logger log.Logger, defaultLogLevelValue string) (
|
||||
if module == defaultLogLevelKey {
|
||||
option, err = log.AllowLevel(level)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, fmt.Sprintf("Failed to parse default log level (pair %s, list %s)", item, l))
|
||||
return nil, fmt.Errorf("failed to parse default log level (pair %s, list %s): %w", item, l, err)
|
||||
}
|
||||
options = append(options, option)
|
||||
isDefaultLogLevelSet = true
|
||||
|
||||
+6
-3
@@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@@ -89,7 +89,10 @@ func (e Executor) Execute() error {
|
||||
err := e.Command.Execute()
|
||||
if err != nil {
|
||||
if viper.GetBool(TraceFlag) {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %+v\n", err)
|
||||
const size = 64 << 10
|
||||
buf := make([]byte, size)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n%s\n", err, buf)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
|
||||
}
|
||||
@@ -151,7 +154,7 @@ func validateOutput(cmd *cobra.Command, args []string) error {
|
||||
switch output {
|
||||
case "text", "json":
|
||||
default:
|
||||
return errors.Errorf("unsupported output format: %s", output)
|
||||
return fmt.Errorf("unsupported output format: %s", output)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -201,10 +200,10 @@ func TestSetupTrace(t *testing.T) {
|
||||
long bool
|
||||
expected string
|
||||
}{
|
||||
{nil, nil, false, "Trace flag = false"},
|
||||
{[]string{"--trace"}, nil, true, "Trace flag = true"},
|
||||
{nil, nil, false, "trace flag = false"},
|
||||
{[]string{"--trace"}, nil, true, "trace flag = true"},
|
||||
{[]string{"--no-such-flag"}, nil, false, "unknown flag: --no-such-flag"},
|
||||
{nil, map[string]string{"DBG_TRACE": "true"}, true, "Trace flag = true"},
|
||||
{nil, map[string]string{"DBG_TRACE": "true"}, true, "trace flag = true"},
|
||||
}
|
||||
|
||||
for idx, tc := range cases {
|
||||
@@ -213,7 +212,7 @@ func TestSetupTrace(t *testing.T) {
|
||||
trace := &cobra.Command{
|
||||
Use: "trace",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return errors.Errorf("Trace flag = %t", viper.GetBool(TraceFlag))
|
||||
return fmt.Errorf("trace flag = %t", viper.GetBool(TraceFlag))
|
||||
},
|
||||
}
|
||||
cmd := PrepareBaseCmd(trace, "DBG", "/qwerty/asdfgh") // some missing dir..
|
||||
@@ -228,10 +227,11 @@ func TestSetupTrace(t *testing.T) {
|
||||
msg := strings.Split(stderr, "\n")
|
||||
desired := fmt.Sprintf("ERROR: %s", tc.expected)
|
||||
assert.Equal(t, desired, msg[0], i)
|
||||
t.Log(msg)
|
||||
if tc.long && assert.True(t, len(msg) > 2, i) {
|
||||
// the next line starts the stack trace...
|
||||
assert.Contains(t, msg[1], "TestSetupTrace", i)
|
||||
assert.Contains(t, msg[2], "setup_test.go", i)
|
||||
assert.Contains(t, stderr, "TestSetupTrace", i)
|
||||
assert.Contains(t, stderr, "setup_test.go", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ package pubsub
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/service"
|
||||
)
|
||||
|
||||
@@ -410,7 +410,7 @@ func (state *state) send(msg interface{}, events map[string][]string) error {
|
||||
|
||||
match, err := q.Matches(events)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to match against query %s", q.String())
|
||||
return fmt.Errorf("failed to match against query %s: %w", q.String(), err)
|
||||
}
|
||||
|
||||
if match {
|
||||
|
||||
@@ -15,8 +15,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -411,7 +409,7 @@ func matchValue(value string, op Operator, operand reflect.Value) (bool, error)
|
||||
v, err = time.Parse(DateLayout, value)
|
||||
}
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to convert value %v from event attribute to time.Time", value)
|
||||
return false, fmt.Errorf("failed to convert value %v from event attribute to time.Time: %w", value, err)
|
||||
}
|
||||
|
||||
switch op {
|
||||
@@ -436,7 +434,7 @@ func matchValue(value string, op Operator, operand reflect.Value) (bool, error)
|
||||
// try our best to convert value from tags to float64
|
||||
v, err := strconv.ParseFloat(filteredValue, 64)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to convert value %v from event attribute to float64", filteredValue)
|
||||
return false, fmt.Errorf("failed to convert value %v from event attribute to float64: %w", filteredValue, err)
|
||||
}
|
||||
|
||||
switch op {
|
||||
@@ -462,7 +460,7 @@ func matchValue(value string, op Operator, operand reflect.Value) (bool, error)
|
||||
if strings.ContainsAny(filteredValue, ".") {
|
||||
v1, err := strconv.ParseFloat(filteredValue, 64)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to convert value %v from event attribute to float64", filteredValue)
|
||||
return false, fmt.Errorf("failed to convert value %v from event attribute to float64: %w", filteredValue, err)
|
||||
}
|
||||
|
||||
v = int64(v1)
|
||||
@@ -471,7 +469,7 @@ func matchValue(value string, op Operator, operand reflect.Value) (bool, error)
|
||||
// try our best to convert value from tags to int64
|
||||
v, err = strconv.ParseInt(filteredValue, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to convert value %v from event attribute to int64", filteredValue)
|
||||
return false, fmt.Errorf("failed to convert value %v from event attribute to int64: %w", filteredValue, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package tempfile
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -4,7 +4,7 @@ package tempfile
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
fmt "fmt"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
testing "testing"
|
||||
|
||||
Reference in New Issue
Block a user