Skip to content

Commit efd5fe1

Browse files
committed
refactor: use errors.New to replace fmt.Errorf with no parameters
Signed-off-by: LesCyber <[email protected]>
1 parent 90b49fc commit efd5fe1

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

x/wasm/client/cli/gov_tx.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,19 @@ func parseVerificationFlags(gzippedWasm []byte, flags *flag.FlagSet) (string, st
114114
// if any set require others to be set
115115
if len(source) != 0 || len(builder) != 0 || len(codeHash) != 0 {
116116
if source == "" {
117-
return "", "", nil, fmt.Errorf("source is required")
117+
return "", "", nil, errors.New("source is required")
118118
}
119119
if _, err = url.ParseRequestURI(source); err != nil {
120120
return "", "", nil, fmt.Errorf("source: %s", err)
121121
}
122122
if builder == "" {
123-
return "", "", nil, fmt.Errorf("builder is required")
123+
return "", "", nil, errors.New("builder is required")
124124
}
125125
if _, err := reference.ParseDockerRef(builder); err != nil {
126126
return "", "", nil, fmt.Errorf("builder: %s", err)
127127
}
128128
if len(codeHash) == 0 {
129-
return "", "", nil, fmt.Errorf("code hash is required")
129+
return "", "", nil, errors.New("code hash is required")
130130
}
131131
// wasm is gzipped in parseStoreCodeArgs
132132
// checksum generation will be decoupled here
@@ -319,10 +319,10 @@ func ProposalStoreAndInstantiateContractCmd() *cobra.Command {
319319

320320
// ensure sensible admin is set (or explicitly immutable)
321321
if adminStr == "" && !noAdmin {
322-
return fmt.Errorf("you must set an admin or explicitly pass --no-admin to make it immutable (wasmd issue #719)")
322+
return errors.New("you must set an admin or explicitly pass --no-admin to make it immutable (wasmd issue #719)")
323323
}
324324
if adminStr != "" && noAdmin {
325-
return fmt.Errorf("you set an admin and passed --no-admin, those cannot both be true")
325+
return errors.New("you set an admin and passed --no-admin, those cannot both be true")
326326
}
327327

328328
if adminStr != "" {

x/wasm/client/cli/query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func GetCmdQueryCode() *cobra.Command {
216216
return err
217217
}
218218
if len(res.Data) == 0 {
219-
return fmt.Errorf("contract not found")
219+
return errors.New("contract not found")
220220
}
221221

222222
fmt.Printf("Downloading wasm code to %s\n", args[1])

x/wasm/client/cli/tx.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func parseStoreCodeArgs(file, sender string, flags *flag.FlagSet) (types.MsgStor
116116
return types.MsgStoreCode{}, err
117117
}
118118
} else if !ioutils.IsGzip(wasm) {
119-
return types.MsgStoreCode{}, fmt.Errorf("invalid input file. Use wasm binary or gzip")
119+
return types.MsgStoreCode{}, errors.New("invalid input file. Use wasm binary or gzip")
120120
}
121121

122122
perm, err := parseAccessConfigFlags(flags)
@@ -202,7 +202,7 @@ func InstantiateContractCmd() *cobra.Command {
202202
Each contract instance has a unique address assigned.
203203
Example:
204204
$ %s tx wasm instantiate 1 '{"foo":"bar"}' --admin="$(%s keys show mykey -a)" \
205-
--from mykey --amount="100ustake" --label "local0.1.0"
205+
--from mykey --amount="100ustake" --label "local0.1.0"
206206
`, version.AppName, version.AppName),
207207
Aliases: []string{"start", "init", "inst", "i"},
208208
Args: cobra.ExactArgs(2),
@@ -236,13 +236,13 @@ func InstantiateContract2Cmd() *cobra.Command {
236236
"--fix-msg [bool,optional]",
237237
Short: "Instantiate a wasm contract with predictable address",
238238
Long: fmt.Sprintf(`Creates a new instance of an uploaded wasm code with the given 'constructor' message.
239-
Each contract instance has a unique address assigned. They are assigned automatically but in order to have predictable addresses
239+
Each contract instance has a unique address assigned. They are assigned automatically but in order to have predictable addresses
240240
for special use cases, the given 'salt' argument and '--fix-msg' parameters can be used to generate a custom address.
241241
242242
Predictable address example (also see '%s query wasm build-address -h'):
243243
$ %s tx wasm instantiate2 1 '{"foo":"bar"}' $(echo -n "testing" | xxd -ps) --admin="$(%s keys show mykey -a)" \
244244
--from mykey --amount="100ustake" --label "local0.1.0" \
245-
--fix-msg
245+
--fix-msg
246246
`, version.AppName, version.AppName, version.AppName),
247247
Aliases: []string{"start", "init", "inst", "i"},
248248
Args: cobra.ExactArgs(3),
@@ -322,10 +322,10 @@ func parseInstantiateArgs(rawCodeID, initMsg string, kr keyring.Keyring, sender
322322

323323
// ensure sensible admin is set (or explicitly immutable)
324324
if adminStr == "" && !noAdmin {
325-
return nil, fmt.Errorf("you must set an admin or explicitly pass --no-admin to make it immutable (wasmd issue #719)")
325+
return nil, errors.New("you must set an admin or explicitly pass --no-admin to make it immutable (wasmd issue #719)")
326326
}
327327
if adminStr != "" && noAdmin {
328-
return nil, fmt.Errorf("you set an admin and passed --no-admin, those cannot both be true")
328+
return nil, errors.New("you set an admin and passed --no-admin, those cannot both be true")
329329
}
330330

331331
if adminStr != "" {
@@ -625,7 +625,7 @@ func parseStoreCodeGrants(args []string) ([]types.CodeGrant, error) {
625625
// access_config: nobody|everybody|address(es)
626626
parts := strings.Split(c, ":")
627627
if len(parts) != 2 {
628-
return nil, fmt.Errorf("invalid format")
628+
return nil, errors.New("invalid format")
629629
}
630630

631631
if parts[1] == "*" {

x/wasm/keeper/wasmtesting/mock_keepers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package wasmtesting
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67

78
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
@@ -137,7 +138,7 @@ func (m *IBCContractKeeperMock) LoadAsyncAckPacket(ctx context.Context, portID,
137138
key := portID + fmt.Sprint(len(channelID)) + channelID
138139
packet, ok := m.packets[key]
139140
if !ok {
140-
return channeltypes.Packet{}, fmt.Errorf("packet not found")
141+
return channeltypes.Packet{}, errors.New("packet not found")
141142
}
142143
return packet, nil
143144
}

x/wasm/module.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package wasm
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"runtime/debug"
89
"strings"
@@ -304,7 +305,7 @@ func getExpectedLibwasmVersion() string {
304305
// `wasmd query wasm libwasmvm-version`.
305306
func CheckLibwasmVersion(wasmExpectedVersion string) error {
306307
if wasmExpectedVersion == "" {
307-
return fmt.Errorf("wasmvm module not exist")
308+
return errors.New("wasmvm module not exist")
308309
}
309310
wasmVersion, err := wasmvm.LibwasmvmVersion()
310311
if err != nil {

x/wasm/types/validation.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package types
22

33
import (
4+
"errors"
45
"fmt"
56
"net/url"
67
"strings"
@@ -80,19 +81,19 @@ func ValidateVerificationInfo(source, builder string, codeHash []byte) error {
8081
// if any set require others to be set
8182
if len(source) != 0 || len(builder) != 0 || len(codeHash) != 0 {
8283
if source == "" {
83-
return fmt.Errorf("source is required")
84+
return errors.New("source is required")
8485
}
8586
if _, err := url.ParseRequestURI(source); err != nil {
8687
return fmt.Errorf("source: %s", err)
8788
}
8889
if builder == "" {
89-
return fmt.Errorf("builder is required")
90+
return errors.New("builder is required")
9091
}
9192
if _, err := reference.ParseDockerRef(builder); err != nil {
9293
return fmt.Errorf("builder: %s", err)
9394
}
9495
if codeHash == nil {
95-
return fmt.Errorf("code hash is required")
96+
return errors.New("code hash is required")
9697
}
9798
// code hash checksum match validation is done in the keeper, ungzipping consumes gas
9899
}

0 commit comments

Comments
 (0)