Skip to content

Commit

Permalink
wip: new #1
Browse files Browse the repository at this point in the history
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
  • Loading branch information
gfanton committed Mar 12, 2024
1 parent 51b236e commit 201fffc
Show file tree
Hide file tree
Showing 35 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/math_eval/int32/int32.gno
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func Eval(expr expression, variables map[string]int) (res int, err error) {
res, ok = variables[ast.Str]
}
if !ok {
err = errors.New(ufmt.Sprintf("variable '%s' not found", ast.Str))
err = fmt.Errorf("variable %q not found", ast.Str)
}
return
case expressionOperation:
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/gnoland/faucet/faucet.gno
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func assertIsController() error {

ok := gControllers.Has(caller.String())
if !ok {
return errors.New(caller.String() + " is not on the controller list")
return errors.New("%q is not on the controller list", caller.String())
}
return nil
}
4 changes: 2 additions & 2 deletions gno.land/cmd/gnofaucet/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ func sendAmountTo(
return fmt.Errorf("broadcasting bytes: %w", err)
}
if bres.CheckTx.IsErr() {
return errors.New("transaction failed %#v\nlog %s", bres, bres.CheckTx.Log)
return fmt.Errorf("transaction failed %#v\nlog %s", bres, bres.CheckTx.Log)
} else if bres.DeliverTx.IsErr() {
return errors.New("transaction failed %#v\nlog %s", bres, bres.DeliverTx.Log)
return fmt.Errorf("transaction failed %#v\nlog %s", bres, bres.DeliverTx.Log)
} else {
io.Println(string(bres.DeliverTx.Data))
io.Println("OK!")
Expand Down
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func runTestFiles(

ret := eval[0].GetString()
if ret == "" {
err := errors.New("failed to execute unit test: %q", test.Name)
err := fmt.Errorf("failed to execute unit test: %q", test.Name)
errs = multierr.Append(errs, err)
io.ErrPrintfln("--- FAIL: %s [internal gno testing error]", test.Name)
continue
Expand All @@ -522,7 +522,7 @@ func runTestFiles(
}

if rep.Failed {
err := errors.New("failed: %q", test.Name)
err := fmt.Errorf("failed: %q", test.Name)
errs = multierr.Append(errs, err)
}

Expand Down
4 changes: 2 additions & 2 deletions gnovm/pkg/gnolang/go2gno.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func ParseExpr(expr string) (retx Expr, err error) {
if rerr, ok := r.(error); ok {
err = rerr
} else {
err = errors.New(fmt.Sprintf("%v", r))
err = fmt.Errorf(fmt.Sprintf("%v", r))
}
return
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func ParseFile(filename string, body string) (fn *FileNode, err error) {
if rerr, ok := r.(error); ok {
fmt.Errorf("parsing file: %w", rerr)
} else {
err = errors.New(fmt.Sprintf("%v", r)).Stacktrace()
err = fmt.Errorf(fmt.Sprintf("%v", r)).Stacktrace()
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (oid ObjectID) MarshalAmino() (string, error) {
func (oid *ObjectID) UnmarshalAmino(oids string) error {
parts := strings.Split(oids, ":")
if len(parts) != 2 {
return errors.New("invalid ObjectID %s", oids)
return fmt.Errorf("invalid ObjectID %s", oids)
}
_, err := hex.Decode(oid.PkgID.Hashlet[:], []byte(parts[0]))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
err = errors.Wrap(rerr, loc.String())
} else {
// NOTE: gotuna/gorilla expects error exceptions.
err = errors.New(fmt.Sprintf("%s: %v", loc.String(), r))
err = fmt.Errorf(fmt.Sprintf("%s: %v", loc.String(), r))
}

// Re-throw the error after wrapping it with the preprocessing stack information.
Expand Down Expand Up @@ -2900,7 +2900,7 @@ func predefineNow(store Store, last BlockNode, d Decl) (Decl, bool) {
panic(errors.Wrap(rerr, loc.String()))
} else {
// NOTE: gotuna/gorilla expects error exceptions.
panic(errors.New(fmt.Sprintf("%s: %v", loc.String(), r)))
panic(fmt.Errorf(fmt.Sprintf("%s: %v", loc.String(), r)))
}
}
}()
Expand Down
6 changes: 3 additions & 3 deletions tm2/pkg/amino/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (cdc *Codec) UnmarshalSized(bz []byte, ptr interface{}) error {
// Read byte-length prefix.
u64, n := binary.Uvarint(bz)
if n < 0 {
return errors.New("Error reading msg byte-length prefix: got code %v", n)
return fmt.Errorf("Error reading msg byte-length prefix: got code %v", n)
}
if u64 > uint64(len(bz)-n) {
return errors.New("Not enough bytes to read in UnmarshalSized, want %v more bytes but only have %v",
Expand Down Expand Up @@ -525,7 +525,7 @@ func (cdc *Codec) UnmarshalSizedReader(r io.Reader, ptr interface{},
}
if maxSize > 0 {
if uint64(maxSize) < u64 {
err = errors.New("read overflow, maxSize is %v but this amino binary object is %v bytes", maxSize, u64)
err = fmt.Errorf("read overflow, maxSize is %v but this amino binary object is %v bytes", maxSize, u64)
return
}
if (maxSize - n) < int64(u64) {
Expand Down Expand Up @@ -573,7 +573,7 @@ func (cdc *Codec) UnmarshalAnySized(bz []byte, ptr interface{}) error {
// Read byte-length prefix.
u64, n := binary.Uvarint(bz)
if n < 0 {
return errors.New("Error reading msg byte-length prefix: got code %v", n)
return fmt.Errorf("Error reading msg byte-length prefix: got code %v", n)
}
if u64 > uint64(len(bz)-n) {
return errors.New("Not enough bytes to read in UnmarshalAnySized, want %v more bytes but only have %v",
Expand Down
8 changes: 4 additions & 4 deletions tm2/pkg/amino/binary_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,11 @@ func (cdc *Codec) decodeReflectBinaryArray(bz []byte, info *TypeInfo, rv reflect
}
// Validate field number and typ3.
if fnum != fopts.BinFieldNum {
err = errors.New(fmt.Sprintf("expected repeated field number %v, got %v", fopts.BinFieldNum, fnum))
err = fmt.Errorf(fmt.Sprintf("expected repeated field number %v, got %v", fopts.BinFieldNum, fnum))
return
}
if typ != Typ3ByteLength {
err = errors.New(fmt.Sprintf("expected repeated field type %v, got %v", Typ3ByteLength, typ))
err = fmt.Errorf(fmt.Sprintf("expected repeated field type %v, got %v", Typ3ByteLength, typ))
return
}
// Decode the next ByteLength bytes into erv.
Expand Down Expand Up @@ -811,11 +811,11 @@ func (cdc *Codec) decodeReflectBinarySlice(bz []byte, info *TypeInfo, rv reflect
}
// Validate field number and typ3.
if fnum < fopts.BinFieldNum {
err = errors.New(fmt.Sprintf("expected repeated field number %v or greater, got %v", fopts.BinFieldNum, fnum))
err = fmt.Errorf(fmt.Sprintf("expected repeated field number %v or greater, got %v", fopts.BinFieldNum, fnum))
return
}
if typ != Typ3ByteLength {
err = errors.New(fmt.Sprintf("expected repeated field type %v, got %v", Typ3ByteLength, typ))
err = fmt.Errorf(fmt.Sprintf("expected repeated field type %v, got %v", Typ3ByteLength, typ))
return
}
// Decode the next ByteLength bytes into erv.
Expand Down
6 changes: 3 additions & 3 deletions tm2/pkg/amino/json_encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (cdc *Codec) encodeReflectJSONInterface(w io.Writer, iinfo *TypeInfo, rv re
return
}
if !cinfo.Registered {
err = errors.New("cannot encode unregistered concrete type %v", crt)
err = fmt.Errorf("cannot encode unregistered concrete type %v", crt)
return
}

Expand All @@ -166,7 +166,7 @@ func (cdc *Codec) encodeReflectJSONInterface(w io.Writer, iinfo *TypeInfo, rv re
if cinfo.IsJSONAnyValueType || (cinfo.IsAminoMarshaler && cinfo.ReprType.IsJSONAnyValueType) {
// Sanity check
if value[0] == '{' || value[len(value)-1] == '}' {
err = errors.New("unexpected JSON object %s", value)
err = fmt.Errorf("unexpected JSON object %s", value)
return
}
// Write TypeURL
Expand All @@ -185,7 +185,7 @@ func (cdc *Codec) encodeReflectJSONInterface(w io.Writer, iinfo *TypeInfo, rv re
} else {
// Sanity check
if value[0] != '{' || value[len(value)-1] != '}' {
err = errors.New("expected JSON object but got %s", value)
err = fmt.Errorf("expected JSON object but got %s", value)
return
}
// Write TypeURL
Expand Down
4 changes: 2 additions & 2 deletions tm2/pkg/bft/consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ func (m *NewValidBlockMessage) ValidateBasic() error {
m.BlockPartsHeader.Total)
}
if m.BlockParts.Size() > types.MaxBlockPartsCount {
return errors.New("BlockParts bit array is too big: %d, max: %d", m.BlockParts.Size(), types.MaxBlockPartsCount)
return fmt.Errorf("BlockParts bit array is too big: %d, max: %d", m.BlockParts.Size(), types.MaxBlockPartsCount)
}
return nil
}
Expand Down Expand Up @@ -1466,7 +1466,7 @@ func (m *ProposalPOLMessage) ValidateBasic() error {
return errors.New("Empty ProposalPOL bit array")
}
if m.ProposalPOL.Size() > types.MaxVotesCount {
return errors.New("ProposalPOL bit array is too big: %d, max: %d", m.ProposalPOL.Size(), types.MaxVotesCount)
return fmt.Errorf("ProposalPOL bit array is too big: %d, max: %d", m.ProposalPOL.Size(), types.MaxVotesCount)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/bft/rpc/client/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Waiter func(delta int64) (abort error)
// but you can plug in another one
func DefaultWaitStrategy(delta int64) (abort error) {
if delta > 10 {
return errors.New("waiting for %d blocks... aborting", delta)
return fmt.Errorf("waiting for %d blocks... aborting", delta)
} else if delta > 0 {
// estimate of wait time....
// wait half a second for the next block (in progress)
Expand Down
12 changes: 6 additions & 6 deletions tm2/pkg/bft/rpc/lib/client/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (c *JSONRPCClient) Call(method string, params map[string]interface{}, resul
defer httpResponse.Body.Close() //nolint: errcheck

if !statusOK(httpResponse.StatusCode) {
return nil, errors.New("server at '%s' returned %s", c.address, httpResponse.Status)
return nil, fmt.Errorf("server at '%s' returned %s", c.address, httpResponse.Status)
}

responseBytes, err := io.ReadAll(httpResponse.Body)
Expand Down Expand Up @@ -235,7 +235,7 @@ func (c *JSONRPCClient) sendBatch(requests []*jsonRPCBufferedRequest) ([]interfa
defer httpResponse.Body.Close() //nolint: errcheck

if !statusOK(httpResponse.StatusCode) {
return nil, errors.New("server at '%s' returned %s", c.address, httpResponse.Status)
return nil, fmt.Errorf("server at '%s' returned %s", c.address, httpResponse.Status)
}

responseBytes, err := io.ReadAll(httpResponse.Body)
Expand Down Expand Up @@ -329,7 +329,7 @@ func (c *URIClient) Call(method string, params map[string]interface{}, result in
defer resp.Body.Close() //nolint: errcheck

if !statusOK(resp.StatusCode) {
return nil, errors.New("server at '%s' returned %s", c.address, resp.Status)
return nil, fmt.Errorf("server at '%s' returned %s", c.address, resp.Status)
}

responseBytes, err := io.ReadAll(resp.Body)
Expand Down Expand Up @@ -380,7 +380,7 @@ func unmarshalResponseBytesArray(responseBytes []byte, expectedID types.JSONRPCS
// and unsuccessful responses.

if len(results) != len(responses) {
return nil, errors.New("expected %d result objects into which to inject responses, but got %d", len(responses), len(results))
return nil, fmt.Errorf("expected %d result objects into which to inject responses, but got %d", len(responses), len(results))
}

for i, response := range responses {
Expand All @@ -407,10 +407,10 @@ func validateResponseID(res *types.RPCResponse, expectedID types.JSONRPCStringID
}
id, ok := res.ID.(types.JSONRPCStringID)
if !ok {
return errors.New("expected ID string in response but got: %v", id)
return fmt.Errorf("expected ID string in response but got: %v", id)
}
if expectedID != id {
return errors.New("response ID (%s) does not match request ID (%s)", id, expectedID)
return fmt.Errorf("response ID (%s) does not match request ID (%s)", id, expectedID)
}
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions tm2/pkg/bft/rpc/lib/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger *slog.Logger) http.H
continue
}
if len(r.URL.Path) > 1 {
responses = append(responses, types.RPCInvalidRequestError(request.ID, errors.New("path %s is invalid", r.URL.Path)))
responses = append(responses, types.RPCInvalidRequestError(request.ID, fmt.Errorf("path %s is invalid", r.URL.Path)))
continue
}
rpcFunc, ok := funcMap[request.Method]
Expand Down Expand Up @@ -207,7 +207,7 @@ func mapParamsToArgs(rpcFunc *RPCFunc, params map[string]json.RawMessage, argsOf

func arrayParamsToArgs(rpcFunc *RPCFunc, params []json.RawMessage, argsOffset int) ([]reflect.Value, error) {
if len(rpcFunc.argNames) != len(params) {
return nil, errors.New("expected %v parameters (%v), got %v (%v)",
return nil, fmt.Errorf("expected %v parameters (%v), got %v (%v)",
len(rpcFunc.argNames), rpcFunc.argNames, len(params), params)
}

Expand Down Expand Up @@ -250,7 +250,7 @@ func jsonParamsToArgs(rpcFunc *RPCFunc, raw []byte) ([]reflect.Value, error) {
}

// Otherwise, bad format, we cannot parse
return nil, errors.New("unknown type for JSON params: %v. Expected map or array", err)
return nil, fmt.Errorf("unknown type for JSON params: %v. Expected map or array", err)
}

// rpc.json
Expand Down Expand Up @@ -814,7 +814,7 @@ func (wm *WebsocketManager) WebsocketHandler(w http.ResponseWriter, r *http.Requ
func unreflectResult(returns []reflect.Value) (interface{}, error) {
errV := returns[1]
if errV.Interface() != nil {
return nil, errors.New("%v", errV.Interface())
return nil, fmt.Errorf("%v", errV.Interface())
}
rv := returns[0]
// If the result is a registered interface, we need a pointer to it so
Expand Down
12 changes: 6 additions & 6 deletions tm2/pkg/bft/rpc/lib/server/http_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetParamInt64(r *http.Request, param string) (int64, error) {
s := GetParam(r, param)
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return 0, errors.New(param, err.Error())
return 0, fmt.Errorf(param, err.Error())
}
return i, nil
}
Expand All @@ -35,7 +35,7 @@ func GetParamInt32(r *http.Request, param string) (int32, error) {
s := GetParam(r, param)
i, err := strconv.ParseInt(s, 10, 32)
if err != nil {
return 0, errors.New(param, err.Error())
return 0, fmt.Errorf(param, err.Error())
}
return int32(i), nil
}
Expand All @@ -44,7 +44,7 @@ func GetParamUint64(r *http.Request, param string) (uint64, error) {
s := GetParam(r, param)
i, err := strconv.ParseUint(s, 10, 64)
if err != nil {
return 0, errors.New(param, err.Error())
return 0, fmt.Errorf(param, err.Error())
}
return i, nil
}
Expand All @@ -53,15 +53,15 @@ func GetParamUint(r *http.Request, param string) (uint, error) {
s := GetParam(r, param)
i, err := strconv.ParseUint(s, 10, 64)
if err != nil {
return 0, errors.New(param, err.Error())
return 0, fmt.Errorf(param, err.Error())
}
return uint(i), nil
}

func GetParamRegexp(r *http.Request, param string, re *regexp.Regexp) (string, error) {
s := GetParam(r, param)
if !re.MatchString(s) {
return "", errors.New(param, "did not match regular expression %v", re.String())
return "", fmt.Errorf(param, "did not match regular expression %v", re.String())
}
return s, nil
}
Expand All @@ -70,7 +70,7 @@ func GetParamFloat64(r *http.Request, param string) (float64, error) {
s := GetParam(r, param)
f, err := strconv.ParseFloat(s, 64)
if err != nil {
return 0, errors.New(param, err.Error())
return 0, fmt.Errorf(param, err.Error())
}
return f, nil
}
2 changes: 1 addition & 1 deletion tm2/pkg/bft/rpc/lib/server/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func Listen(addr string, config *Config) (listener net.Listener, err error) {
proto, addr := parts[0], parts[1]
listener, err = net.Listen(proto, addr)
if err != nil {
return nil, errors.New("failed to listen on %v: %v", addr, err)
return nil, fmt.Errorf("failed to listen on %v: %v", addr, err)
}
if config.MaxOpenConnections > 0 {
listener = netutil.LimitListener(listener, config.MaxOpenConnections)
Expand Down
6 changes: 3 additions & 3 deletions tm2/pkg/bft/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
return errors.New("Genesis doc must include non-empty chain_id")
}
if len(genDoc.ChainID) > MaxChainIDLen {
return errors.New("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen)
return fmt.Errorf("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen)
}

// Start from defaults and fill in consensus params from GenesisDoc.
Expand All @@ -137,12 +137,12 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {

for i, v := range genDoc.Validators {
if v.Power == 0 {
return errors.New("The genesis file cannot contain validators with no voting power: %v", v)
return fmt.Errorf("The genesis file cannot contain validators with no voting power: %v", v)
}
if v.Address.IsZero() {
genDoc.Validators[i].Address = v.PubKey.Address()
} else if v.PubKey.Address() != v.Address {
return errors.New("Incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address())
return fmt.Errorf("Incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address())
}
}

Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/bft/types/part_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (part *Part) ValidateBasic() error {
return errors.New("negative Index")
}
if len(part.Bytes) > BlockPartSizeBytes {
return errors.New("too big: %d bytes, max: %d", len(part.Bytes), BlockPartSizeBytes)
return fmt.Errorf("too big: %d bytes, max: %d", len(part.Bytes), BlockPartSizeBytes)
}
if err := part.Proof.ValidateBasic(); err != nil {
return fmt.Errorf("wrong Proof: %w", err)
Expand Down
Loading

0 comments on commit 201fffc

Please sign in to comment.