Errorf -> fmt.Errorf

This commit is contained in:
Jae Kwon 2015-04-15 21:49:14 -07:00
parent 58bcad3ea3
commit df1d46d04d
7 changed files with 20 additions and 25 deletions

View File

@ -151,7 +151,7 @@ func RunProcess(wait bool, label string, execPath string, args []string, input s
existing := barak.processes[label] existing := barak.processes[label]
if existing != nil { if existing != nil {
barak.mtx.Unlock() barak.mtx.Unlock()
return nil, Errorf("Process already exists: %v", label) return nil, fmt.Errorf("Process already exists: %v", label)
} }
// Otherwise, create one. // Otherwise, create one.
@ -173,7 +173,7 @@ func StopProcess(label string, kill bool) (*ResponseStopProcess, error) {
barak.mtx.Unlock() barak.mtx.Unlock()
if proc == nil { if proc == nil {
return nil, Errorf("Process does not exist: %v", label) return nil, fmt.Errorf("Process does not exist: %v", label)
} }
err := pcm.Stop(proc, kill) err := pcm.Stop(proc, kill)

View File

@ -27,7 +27,7 @@ func GetNonce(remote string) uint64 {
response := btypes.ResponseStatus{} response := btypes.ResponseStatus{}
_, err = rpc.Call(remote, "status", Arr(), &response) _, err = rpc.Call(remote, "status", Arr(), &response)
if err != nil { if err != nil {
panic(Fmt("Error fetching nonce from remote %v: %v", remote, err)) Exit(Fmt("Error fetching nonce from remote %v: %v", remote, err))
} }
return response.Nonce return response.Nonce
} }

View File

@ -1,14 +1,9 @@
package common package common
import ( import (
"errors"
"fmt" "fmt"
) )
func Errorf(s string, args ...interface{}) error {
return errors.New(fmt.Sprintf(s, args...))
}
type StackError struct { type StackError struct {
Err interface{} Err interface{}
Stack []byte Stack []byte

View File

@ -33,7 +33,7 @@ type POL struct {
func (pol *POL) Verify(valSet *sm.ValidatorSet) error { func (pol *POL) Verify(valSet *sm.ValidatorSet) error {
if uint(len(pol.Votes)) != valSet.Size() { if uint(len(pol.Votes)) != valSet.Size() {
return Errorf("Invalid POL votes count: Expected %v, got %v", return fmt.Errorf("Invalid POL votes count: Expected %v, got %v",
valSet.Size(), len(pol.Votes)) valSet.Size(), len(pol.Votes))
} }
@ -61,16 +61,16 @@ func (pol *POL) Verify(valSet *sm.ValidatorSet) error {
BlockParts: pol.BlockParts, BlockParts: pol.BlockParts,
}) })
} else if vote.Round > pol.Round { } else if vote.Round > pol.Round {
return Errorf("Invalid commit round %v for POL %v", vote.Round, pol) return fmt.Errorf("Invalid commit round %v for POL %v", vote.Round, pol)
} }
// Validate // Validate
if _, seen := seenValidators[string(val.Address)]; seen { if _, seen := seenValidators[string(val.Address)]; seen {
return Errorf("Duplicate validator for vote %v for POL %v", vote, pol) return fmt.Errorf("Duplicate validator for vote %v for POL %v", vote, pol)
} }
if !val.PubKey.VerifyBytes(voteDoc, vote.Signature) { if !val.PubKey.VerifyBytes(voteDoc, vote.Signature) {
return Errorf("Invalid signature for vote %v for POL %v", vote, pol) return fmt.Errorf("Invalid signature for vote %v for POL %v", vote, pol)
} }
// Tally // Tally
@ -81,7 +81,7 @@ func (pol *POL) Verify(valSet *sm.ValidatorSet) error {
if talliedVotingPower > valSet.TotalVotingPower()*2/3 { if talliedVotingPower > valSet.TotalVotingPower()*2/3 {
return nil return nil
} else { } else {
return Errorf("Invalid POL, insufficient voting power %v, needed %v", return fmt.Errorf("Invalid POL, insufficient voting power %v, needed %v",
talliedVotingPower, (valSet.TotalVotingPower()*2/3 + 1)) talliedVotingPower, (valSet.TotalVotingPower()*2/3 + 1))
} }

View File

@ -2,11 +2,10 @@ package rpc
import ( import (
"encoding/hex" "encoding/hex"
"fmt"
"net/http" "net/http"
"regexp" "regexp"
"strconv" "strconv"
. "github.com/tendermint/tendermint/common"
) )
var ( var (
@ -44,7 +43,7 @@ func GetParamInt64(r *http.Request, param string) (int64, error) {
s := GetParam(r, param) s := GetParam(r, param)
i, err := strconv.ParseInt(s, 10, 64) i, err := strconv.ParseInt(s, 10, 64)
if err != nil { if err != nil {
return 0, Errorf(param, err.Error()) return 0, fmt.Errorf(param, err.Error())
} }
return i, nil return i, nil
} }
@ -53,7 +52,7 @@ func GetParamInt32(r *http.Request, param string) (int32, error) {
s := GetParam(r, param) s := GetParam(r, param)
i, err := strconv.ParseInt(s, 10, 32) i, err := strconv.ParseInt(s, 10, 32)
if err != nil { if err != nil {
return 0, Errorf(param, err.Error()) return 0, fmt.Errorf(param, err.Error())
} }
return int32(i), nil return int32(i), nil
} }
@ -62,7 +61,7 @@ func GetParamUint64(r *http.Request, param string) (uint64, error) {
s := GetParam(r, param) s := GetParam(r, param)
i, err := strconv.ParseUint(s, 10, 64) i, err := strconv.ParseUint(s, 10, 64)
if err != nil { if err != nil {
return 0, Errorf(param, err.Error()) return 0, fmt.Errorf(param, err.Error())
} }
return i, nil return i, nil
} }
@ -71,7 +70,7 @@ func GetParamUint(r *http.Request, param string) (uint, error) {
s := GetParam(r, param) s := GetParam(r, param)
i, err := strconv.ParseUint(s, 10, 64) i, err := strconv.ParseUint(s, 10, 64)
if err != nil { if err != nil {
return 0, Errorf(param, err.Error()) return 0, fmt.Errorf(param, err.Error())
} }
return uint(i), nil return uint(i), nil
} }
@ -79,7 +78,7 @@ func GetParamUint(r *http.Request, param string) (uint, error) {
func GetParamRegexp(r *http.Request, param string, re *regexp.Regexp) (string, error) { func GetParamRegexp(r *http.Request, param string, re *regexp.Regexp) (string, error) {
s := GetParam(r, param) s := GetParam(r, param)
if !re.MatchString(s) { if !re.MatchString(s) {
return "", Errorf(param, "Did not match regular expression %v", re.String()) return "", fmt.Errorf(param, "Did not match regular expression %v", re.String())
} }
return s, nil return s, nil
} }
@ -88,7 +87,7 @@ func GetParamFloat64(r *http.Request, param string) (float64, error) {
s := GetParam(r, param) s := GetParam(r, param)
f, err := strconv.ParseFloat(s, 64) f, err := strconv.ParseFloat(s, 64)
if err != nil { if err != nil {
return 0, Errorf(param, err.Error()) return 0, fmt.Errorf(param, err.Error())
} }
return f, nil return f, nil
} }

View File

@ -3,6 +3,7 @@ package state
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt"
"github.com/tendermint/tendermint/account" "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
@ -20,7 +21,7 @@ func ExecBlock(s *State, block *types.Block, blockPartsHeader types.PartSetHeade
// State.Hash should match block.StateHash // State.Hash should match block.StateHash
stateHash := s.Hash() stateHash := s.Hash()
if !bytes.Equal(stateHash, block.StateHash) { if !bytes.Equal(stateHash, block.StateHash) {
return Errorf("Invalid state hash. Expected %X, got %X", return fmt.Errorf("Invalid state hash. Expected %X, got %X",
stateHash, block.StateHash) stateHash, block.StateHash)
} }
return nil return nil

View File

@ -225,11 +225,11 @@ func (valSet *ValidatorSet) VerifyValidation(hash []byte, parts types.PartSetHea
// Validate // Validate
if _, seen := seenValidators[string(val.Address)]; seen { if _, seen := seenValidators[string(val.Address)]; seen {
return Errorf("Duplicate validator for commit %v for Validation %v", commit, v) return fmt.Errorf("Duplicate validator for commit %v for Validation %v", commit, v)
} }
if !val.PubKey.VerifyBytes(commitSignBytes, commit.Signature) { if !val.PubKey.VerifyBytes(commitSignBytes, commit.Signature) {
return Errorf("Invalid signature for commit %v for Validation %v", commit, v) return fmt.Errorf("Invalid signature for commit %v for Validation %v", commit, v)
} }
// Tally // Tally
@ -240,7 +240,7 @@ func (valSet *ValidatorSet) VerifyValidation(hash []byte, parts types.PartSetHea
if talliedVotingPower > valSet.TotalVotingPower()*2/3 { if talliedVotingPower > valSet.TotalVotingPower()*2/3 {
return nil return nil
} else { } else {
return Errorf("insufficient voting power %v, needed %v", return fmt.Errorf("insufficient voting power %v, needed %v",
talliedVotingPower, (valSet.TotalVotingPower()*2/3 + 1)) talliedVotingPower, (valSet.TotalVotingPower()*2/3 + 1))
} }
} }