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:
Anton Kaliaev
2020-05-12 03:35:47 +00:00
committed by GitHub
parent 8d63d7192f
commit b7b721c484
90 changed files with 321 additions and 391 deletions
+3 -3
View File
@@ -1,13 +1,13 @@
package debug
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -55,13 +55,13 @@ func dumpCmdHandler(_ *cobra.Command, args []string) error {
if _, err := os.Stat(outDir); os.IsNotExist(err) {
if err := os.Mkdir(outDir, os.ModePerm); err != nil {
return errors.Wrap(err, "failed to create output directory")
return fmt.Errorf("failed to create output directory: %w", err)
}
}
rpc, err := rpchttp.New(nodeRPCAddr, "/websocket")
if err != nil {
return errors.Wrap(err, "failed to create new http client")
return fmt.Errorf("failed to create new http client: %w", err)
}
home := viper.GetString(cli.HomeFlag)
+2 -3
View File
@@ -3,14 +3,13 @@ package debug
import (
"archive/zip"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"github.com/pkg/errors"
)
// zipDir zips all the contents found in src, including both files and
@@ -110,7 +109,7 @@ func copyFile(src, dest string) error {
func writeStateJSONToFile(state interface{}, dir, filename string) error {
stateJSON, err := json.MarshalIndent(state, "", " ")
if err != nil {
return errors.Wrap(err, "failed to encode state dump")
return fmt.Errorf("failed to encode state dump: %w", err)
}
return ioutil.WriteFile(path.Join(dir, filename), stateJSON, os.ModePerm)
+3 -3
View File
@@ -1,6 +1,7 @@
package debug
import (
"errors"
"fmt"
"io/ioutil"
"os"
@@ -10,7 +11,6 @@ import (
"syscall"
"time"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -46,7 +46,7 @@ func killCmdHandler(cmd *cobra.Command, args []string) error {
rpc, err := rpchttp.New(nodeRPCAddr, "/websocket")
if err != nil {
return errors.Wrap(err, "failed to create new http client")
return fmt.Errorf("failed to create new http client: %w", err)
}
home := viper.GetString(cli.HomeFlag)
@@ -58,7 +58,7 @@ func killCmdHandler(cmd *cobra.Command, args []string) error {
// relevant files and directories that will be compressed into a file.
tmpDir, err := ioutil.TempDir(os.TempDir(), "tendermint_debug_tmp")
if err != nil {
return errors.Wrap(err, "failed to create temporary directory")
return fmt.Errorf("failed to create temporary directory: %w", err)
}
defer os.RemoveAll(tmpDir)
+5 -7
View File
@@ -8,8 +8,6 @@ import (
"path"
"path/filepath"
"github.com/pkg/errors"
cfg "github.com/tendermint/tendermint/config"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
)
@@ -19,7 +17,7 @@ import (
func dumpStatus(rpc *rpchttp.HTTP, dir, filename string) error {
status, err := rpc.Status()
if err != nil {
return errors.Wrap(err, "failed to get node status")
return fmt.Errorf("failed to get node status: %w", err)
}
return writeStateJSONToFile(status, dir, filename)
@@ -30,7 +28,7 @@ func dumpStatus(rpc *rpchttp.HTTP, dir, filename string) error {
func dumpNetInfo(rpc *rpchttp.HTTP, dir, filename string) error {
netInfo, err := rpc.NetInfo()
if err != nil {
return errors.Wrap(err, "failed to get node network information")
return fmt.Errorf("failed to get node network information: %w", err)
}
return writeStateJSONToFile(netInfo, dir, filename)
@@ -41,7 +39,7 @@ func dumpNetInfo(rpc *rpchttp.HTTP, dir, filename string) error {
func dumpConsensusState(rpc *rpchttp.HTTP, dir, filename string) error {
consDump, err := rpc.DumpConsensusState()
if err != nil {
return errors.Wrap(err, "failed to get node consensus dump")
return fmt.Errorf("failed to get node consensus dump: %w", err)
}
return writeStateJSONToFile(consDump, dir, filename)
@@ -70,13 +68,13 @@ func dumpProfile(dir, addr, profile string, debug int) error {
resp, err := http.Get(endpoint) // nolint: gosec
if err != nil {
return errors.Wrapf(err, "failed to query for %s profile", profile)
return fmt.Errorf("failed to query for %s profile: %w", profile, err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return errors.Wrapf(err, "failed to read %s profile response body", profile)
return fmt.Errorf("failed to read %s profile response body: %w", profile, err)
}
return ioutil.WriteFile(path.Join(dir, fmt.Sprintf("%s.out", profile)), body, os.ModePerm)
+1 -2
View File
@@ -3,7 +3,6 @@ package commands
import (
"fmt"
"github.com/pkg/errors"
"github.com/spf13/cobra"
cfg "github.com/tendermint/tendermint/config"
@@ -64,7 +63,7 @@ func initFilesWithConfig(config *cfg.Config) error {
}
pubKey, err := pv.GetPubKey()
if err != nil {
return errors.Wrap(err, "can't get pubkey")
return fmt.Errorf("can't get pubkey: %w", err)
}
genDoc.Validators = []types.GenesisValidator{{
Address: pubKey.Address(),
+3 -3
View File
@@ -1,12 +1,12 @@
package commands
import (
"fmt"
"net/http"
"os"
"strings"
"time"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/tendermint/go-amino"
@@ -102,7 +102,7 @@ func runProxy(cmd *cobra.Command, args []string) error {
db, err := dbm.NewGoLevelDB("lite-client-db", home)
if err != nil {
return errors.Wrap(err, "new goleveldb")
return fmt.Errorf("new goleveldb: %w", err)
}
var c *lite.Client
@@ -135,7 +135,7 @@ func runProxy(cmd *cobra.Command, args []string) error {
rpcClient, err := rpchttp.New(primaryAddr, "/websocket")
if err != nil {
return errors.Wrapf(err, "http client for %s", primaryAddr)
return fmt.Errorf("http client for %s: %w", primaryAddr, err)
}
p := lproxy.Proxy{
Addr: listenAddr,
+3 -4
View File
@@ -7,7 +7,6 @@ import (
"io"
"os"
"github.com/pkg/errors"
"github.com/spf13/cobra"
cfg "github.com/tendermint/tendermint/config"
@@ -138,18 +137,18 @@ func checkGenesisHash(config *cfg.Config) error {
// Calculate SHA-256 hash of the genesis file.
f, err := os.Open(config.GenesisFile())
if err != nil {
return errors.Wrap(err, "can't open genesis file")
return fmt.Errorf("can't open genesis file: %w", err)
}
defer f.Close()
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
return errors.Wrap(err, "error when hashing genesis file")
return fmt.Errorf("error when hashing genesis file: %w", err)
}
actualHash := h.Sum(nil)
// Compare with the flag.
if !bytes.Equal(genesisHash, actualHash) {
return errors.Errorf(
return fmt.Errorf(
"--genesis_hash=%X does not match %s hash: %X",
genesisHash, config.GenesisFile(), actualHash)
}
+2 -3
View File
@@ -3,7 +3,6 @@ package commands
import (
"fmt"
"github.com/pkg/errors"
"github.com/spf13/cobra"
tmos "github.com/tendermint/tendermint/libs/os"
@@ -27,12 +26,12 @@ func showValidator(cmd *cobra.Command, args []string) error {
pubKey, err := pv.GetPubKey()
if err != nil {
return errors.Wrap(err, "can't get pubkey")
return fmt.Errorf("can't get pubkey: %w", err)
}
bz, err := cdc.MarshalJSON(pubKey)
if err != nil {
return errors.Wrap(err, "failed to marshal private validator pubkey")
return fmt.Errorf("failed to marshal private validator pubkey: %w", err)
}
fmt.Println(string(bz))
+1 -2
View File
@@ -7,7 +7,6 @@ import (
"path/filepath"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -142,7 +141,7 @@ func testnetFiles(cmd *cobra.Command, args []string) error {
pubKey, err := pv.GetPubKey()
if err != nil {
return errors.Wrap(err, "can't get pubkey")
return fmt.Errorf("can't get pubkey: %w", err)
}
genVals[i] = types.GenesisValidator{
Address: pubKey.Address(),