Skip to content

Commit

Permalink
util: remove Error
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed Sep 3, 2015
1 parent 9017ef6 commit a41b734
Show file tree
Hide file tree
Showing 28 changed files with 47 additions and 68 deletions.
2 changes: 1 addition & 1 deletion acceptance/localcluster/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func dockerIP() net.IP {
if runtime.GOOS == "linux" {
return net.IPv4zero
}
panic(fmt.Errorf("unable to determine docker ip address"))
panic("unable to determine docker ip address")
}

// Container provides the programmatic interface for a single docker
Expand Down
4 changes: 2 additions & 2 deletions gossip/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *client) start(g *Gossip, done chan *client, context *rpc.Context, stopp
c.rpcClient.Close()
}
case <-c.rpcClient.Closed:
err = util.Error("client closed")
err = util.Errorf("client closed")
}

done <- c
Expand Down Expand Up @@ -120,7 +120,7 @@ func (c *client) gossip(g *Gossip, stopper *stop.Stopper) error {
return gossipCall.Error
}
case <-c.rpcClient.Closed:
return util.Error("client closed")
return util.Errorf("client closed")
case <-c.closer:
return nil
case <-stopper.ShouldStop():
Expand Down
2 changes: 1 addition & 1 deletion kv/dist_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (ds *DistSender) getDescriptors(call proto.Call) (*proto.RangeDescriptor, *
// get the descriptor of the adjacent range to address next.
if nextKey, ok := needAnother(desc, isReverseScan); ok {
if _, ok := call.Reply.(proto.Combinable); !ok {
return nil, nil, util.Error("illegal cross-range operation")
return nil, nil, util.Errorf("illegal cross-range operation")
}
// If there's no transaction and op spans ranges, possibly
// re-run as part of a transaction for consistency. The
Expand Down
4 changes: 2 additions & 2 deletions kv/txn_coord_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ func updateForBatch(args proto.Request, bHeader proto.RequestHeader) error {
// equal.
aHeader := args.Header()
if aPrio := aHeader.GetUserPriority(); aPrio != proto.Default_RequestHeader_UserPriority && aPrio != bHeader.GetUserPriority() {
return util.Error("conflicting user priority on call in batch")
return util.Errorf("conflicting user priority on call in batch")
}
aHeader.UserPriority = bHeader.UserPriority
// Only allow individual transactions on the requests of a batch if
Expand All @@ -573,7 +573,7 @@ func updateForBatch(args proto.Request, bHeader proto.RequestHeader) error {
// entails sending a non-txn batch of transactional InternalResolveIntent.
if aHeader.Txn != nil && !aHeader.Txn.Equal(bHeader.Txn) {
if len(aHeader.Txn.ID) == 0 || proto.IsTransactionWrite(args) || bHeader.Txn != nil {
return util.Error("conflicting transaction in transactional batch")
return util.Errorf("conflicting transaction in transactional batch")
}
} else {
aHeader.Txn = bHeader.Txn
Expand Down
10 changes: 5 additions & 5 deletions multiraft/multiraft.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ type Config struct {
// Called automatically by NewMultiRaft.
func (c *Config) validate() error {
if c.Transport == nil {
return util.Error("Transport is required")
return util.Errorf("Transport is required")
}
if c.ElectionTimeoutTicks == 0 {
return util.Error("ElectionTimeoutTicks must be non-zero")
return util.Errorf("ElectionTimeoutTicks must be non-zero")
}
if c.HeartbeatIntervalTicks == 0 {
return util.Error("HeartbeatIntervalTicks must be non-zero")
return util.Errorf("HeartbeatIntervalTicks must be non-zero")
}
if c.TickInterval == 0 {
return util.Error("TickInterval must be non-zero")
return util.Errorf("TickInterval must be non-zero")
}
return nil
}
Expand Down Expand Up @@ -119,7 +119,7 @@ type multiraftServer MultiRaft
// NewMultiRaft creates a MultiRaft object.
func NewMultiRaft(nodeID proto.RaftNodeID, config *Config, stopper *stop.Stopper) (*MultiRaft, error) {
if nodeID == 0 {
return nil, util.Error("Invalid RaftNodeID")
return nil, util.Errorf("Invalid RaftNodeID")
}
if err := config.validate(); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion rpc/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func Send(opts Options, method string, addrs []net.Addr, getArgs func(addr net.A
call.Error = err
}
} else {
call.Error = util.Error("response to proto request must be a proto")
call.Error = util.Errorf("response to proto request must be a proto")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ type BrokenResponse struct {
}

func (*BrokenResponse) Verify() error {
return util.Error("boom")
return util.Errorf("boom")
}

// TestUnretryableError verifies that Send returns an unretryable
Expand Down
4 changes: 2 additions & 2 deletions security/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func newServerTLSConfig(certPEM, keyPEM, caPEM []byte) (*tls.Config, error) {
certPool := x509.NewCertPool()

if ok := certPool.AppendCertsFromPEM(caPEM); !ok {
err = util.Error("failed to parse PEM data to pool")
err = util.Errorf("failed to parse PEM data to pool")
return nil, err
}

Expand Down Expand Up @@ -150,7 +150,7 @@ func newClientTLSConfig(certPEM, keyPEM, caPEM []byte) (*tls.Config, error) {
certPool := x509.NewCertPool()

if ok := certPool.AppendCertsFromPEM(caPEM); !ok {
err := util.Error("failed to parse PEM data to pool")
err := util.Errorf("failed to parse PEM data to pool")
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion server/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func (n *Node) initStores(engines []engine.Engine, stopper *stop.Stopper) error
bootstraps := list.New()

if len(engines) == 0 {
return util.Error("no engines")
return util.Errorf("no engines")
}
for _, e := range engines {
s := storage.NewStore(n.ctx, e, &n.Descriptor)
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type Server struct {
// NewServer creates a Server from a server.Context.
func NewServer(ctx *Context, stopper *stop.Stopper) (*Server, error) {
if ctx == nil {
return nil, util.Error("ctx must not be null")
return nil, util.Errorf("ctx must not be null")
}

addr := ctx.Addr
Expand Down
4 changes: 0 additions & 4 deletions sql/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ func (p *planner) getDescriptorFromTargetList(targets parser.TargetList) (descri
return descriptor, nil
}

if targets.Tables == nil {
return nil, fmt.Errorf("no targets specified")
}

if len(targets.Tables) == 0 {
return nil, errNoTable
} else if len(targets.Tables) != 1 {
Expand Down
7 changes: 5 additions & 2 deletions sql/parser/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"errors"
"fmt"
"math/rand"
"reflect"
"strings"
)

var errEmptyInputString = errors.New("the input string should not be empty")

type typeList []reflect.Type

type builtin struct {
Expand Down Expand Up @@ -158,7 +161,7 @@ var builtins = map[string][]builtin{
field := int(args[2].(DInt))

if field <= 0 {
return DNull, fmt.Errorf("field position must be greater than zero")
return DNull, fmt.Errorf("field position %d must be greater than zero", field)
}

splits := strings.Split(text, sep)
Expand Down Expand Up @@ -189,7 +192,7 @@ var builtins = map[string][]builtin{
for _, ch := range s {
return DInt(ch), nil
}
return nil, fmt.Errorf("the input string should not be empty")
return nil, errEmptyInputString
}, DummyInt)},

"md5": {stringBuiltin1(func(s string) (Datum, error) {
Expand Down
2 changes: 1 addition & 1 deletion sql/parser/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ func ParseTimestamp(s DString) (DTimestamp, error) {
// and it's not clear what are the memory requirements for that.
// TODO(vivek): Implement SET TIME ZONE to set a time zone and use
// time.ParseInLocation()
return DummyTimestamp, util.Error("TODO(vivek): named time zone input not supported")
return DummyTimestamp, util.Errorf("TODO(vivek): named time zone input not supported")
}
// Parse other formats in the future.
return DummyTimestamp, err
Expand Down
3 changes: 0 additions & 3 deletions sql/privilege.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ func (p *PrivilegeDescriptor) Revoke(user string, privList privilege.List) {
// it belongs to a system descriptor, in which case the maximum
// set of allowed privileges is looked up and applied.
func (p *PrivilegeDescriptor) Validate(id ID) error {
if p == nil {
return fmt.Errorf("missing privilege descriptor")
}
userPriv, ok := p.findUser(security.RootUser)
if !ok {
return fmt.Errorf("user %s does not have privileges", security.RootUser)
Expand Down
16 changes: 8 additions & 8 deletions sql/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const (
PrimaryKeyIndexName = "primary"
)

// ErrMissingPrimaryKey exported to the sql package.
var ErrMissingPrimaryKey = errors.New("table must contain a primary key")
var errMissingColumns = errors.New("table must contain at least 1 column")
var errMissingPrimaryKey = errors.New("table must contain a primary key")

func validateName(name, typ string) error {
if len(name) == 0 {
Expand Down Expand Up @@ -213,11 +213,11 @@ func (desc *TableDescriptor) Validate() error {
return err
}
if desc.ID == 0 {
return fmt.Errorf("invalid table ID 0")
return fmt.Errorf("invalid table ID %d", desc.ID)
}

if len(desc.Columns) == 0 {
return fmt.Errorf("table must contain at least 1 column")
return errMissingColumns
}

columnNames := map[string]ColumnID{}
Expand All @@ -227,7 +227,7 @@ func (desc *TableDescriptor) Validate() error {
return err
}
if column.ID == 0 {
return fmt.Errorf("invalid column ID 0")
return fmt.Errorf("invalid column ID %d", column.ID)
}

if _, ok := columnNames[column.Name]; ok {
Expand All @@ -250,7 +250,7 @@ func (desc *TableDescriptor) Validate() error {
// TODO(pmattis): Check that the indexes are unique. That is, no 2 indexes
// should contain identical sets of columns.
if len(desc.PrimaryIndex.ColumnIDs) == 0 {
return ErrMissingPrimaryKey
return errMissingPrimaryKey
}

indexNames := map[string]struct{}{}
Expand All @@ -260,7 +260,7 @@ func (desc *TableDescriptor) Validate() error {
return err
}
if index.ID == 0 {
return fmt.Errorf("invalid index ID 0")
return fmt.Errorf("invalid index ID %d", index.ID)
}

if _, ok := indexNames[index.Name]; ok {
Expand Down Expand Up @@ -378,7 +378,7 @@ func (desc *DatabaseDescriptor) Validate() error {
return err
}
if desc.ID == 0 {
return fmt.Errorf("invalid database ID 0")
return fmt.Errorf("invalid database ID %d", desc.ID)
}
// Validate the privilege descriptor.
return desc.Privileges.Validate(desc.GetID())
Expand Down
2 changes: 1 addition & 1 deletion sql/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestPrimaryKeyUnspecified(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := desc.AllocateIDs(); err != ErrMissingPrimaryKey {
if err := desc.AllocateIDs(); err != errMissingPrimaryKey {
t.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion storage/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (a allocator) rebalanceTarget(required proto.Attributes, existing []proto.R
// requirements (i.e. multiple data centers).
func (a allocator) removeTarget(existing []proto.Replica) (proto.Replica, error) {
if len(existing) == 0 {
return proto.Replica{}, util.Error("must supply at least one replica to allocator.RemoveTarget()")
return proto.Replica{}, util.Errorf("must supply at least one replica to allocator.RemoveTarget()")
}

// Retrieve store descriptors for the provided replicas from the StorePool.
Expand Down
2 changes: 1 addition & 1 deletion storage/client_range_gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestRangeGCQueueDropReplica(t *testing.T) {
// Make sure the range is removed from the store.
util.SucceedsWithin(t, time.Second, func() error {
if _, err := mtc.stores[1].GetReplica(rangeID); !testutils.IsError(err, "range .* was not found") {
return util.Error("expected range removal")
return util.Errorf("expected range removal")
}
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion storage/client_split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func TestStoreRangeSplitWithMaxBytesUpdate(t *testing.T) {
util.SucceedsWithin(t, time.Second, func() error {
newRng := store.LookupReplica(proto.Key("db1"), nil)
if newRng.Desc().RangeID == origRng.Desc().RangeID {
return util.Error("expected new range created by split")
return util.Errorf("expected new range created by split")
}
if newRng.GetMaxBytes() != maxBytes {
return util.Errorf("expected %d max bytes for the new range, but got %d",
Expand Down
4 changes: 2 additions & 2 deletions storage/engine/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ func MVCCResolveWriteIntent(engine Engine, ms *MVCCStats, key proto.Key, timesta
return emptyKeyError()
}
if txn == nil {
return util.Error("no txn specified")
return util.Errorf("no txn specified")
}

metaKey := MVCCEncodeKey(key)
Expand Down Expand Up @@ -1327,7 +1327,7 @@ func MVCCResolveWriteIntent(engine Engine, ms *MVCCStats, key proto.Key, timesta
// txns. Specify max=0 for unbounded resolves.
func MVCCResolveWriteIntentRange(engine Engine, ms *MVCCStats, key, endKey proto.Key, max int64, timestamp proto.Timestamp, txn *proto.Transaction) (int64, error) {
if txn == nil {
return 0, util.Error("no txn specified")
return 0, util.Errorf("no txn specified")
}

encKey := MVCCEncodeKey(key)
Expand Down
2 changes: 1 addition & 1 deletion storage/range_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (tc *treeContext) getUncle(node *proto.RangeTreeNode) (*proto.RangeTreeNode
func (tc *treeContext) replaceNode(oldNode, newNode *proto.RangeTreeNode) (*proto.RangeTreeNode, error) {
if oldNode.ParentKey == nil {
if newNode == nil {
return nil, util.Error("cannot replace the root node with nil")
return nil, util.Errorf("cannot replace the root node with nil")
}
// Update the root key if this was the root.
tc.setRootKey(newNode.Key)
Expand Down
6 changes: 3 additions & 3 deletions storage/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ func (r *Replica) addAdminCmd(ctx context.Context, args proto.Request) (proto.Re
resp, err := r.AdminMerge(*tArgs, r.Desc())
return &resp, err
default:
return nil, util.Error("unrecognized admin command")
return nil, util.Errorf("unrecognized admin command")
}
}

Expand All @@ -618,7 +618,7 @@ func (r *Replica) addReadOnlyCmd(ctx context.Context, args proto.Request) (proto
if header.ReadConsistency == proto.INCONSISTENT {
// But disallow any inconsistent reads within txns.
if header.Txn != nil {
return nil, util.Error("cannot allow inconsistent reads within a transaction")
return nil, util.Errorf("cannot allow inconsistent reads within a transaction")
}
if header.Timestamp.Equal(proto.ZeroTimestamp) {
header.Timestamp = r.rm.Clock().Now()
Expand All @@ -627,7 +627,7 @@ func (r *Replica) addReadOnlyCmd(ctx context.Context, args proto.Request) (proto
r.handleSkippedIntents(args, intents) // even on error
return reply, err
} else if header.ReadConsistency == proto.CONSENSUS {
return nil, util.Error("consensus reads not implemented")
return nil, util.Errorf("consensus reads not implemented")
}

// Add the read to the command queue to gate subsequent
Expand Down
4 changes: 2 additions & 2 deletions storage/replica_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ func (r *Replica) PushTxn(batch engine.Engine, ms *engine.MVCCStats, args proto.
reply.PusheeTxn.LastHeartbeat = &reply.PusheeTxn.Timestamp
}
if args.Now.Equal(proto.ZeroTimestamp) {
return reply, util.Error("the field Now must be provided")
return reply, util.Errorf("the field Now must be provided")
}
// Compute heartbeat expiration (all replicas must see the same result).
expiry := args.Now
Expand Down Expand Up @@ -1261,7 +1261,7 @@ func (r *Replica) AdminMerge(args proto.AdminMergeRequest, desc *proto.RangeDesc
// Ensure that both ranges are collocate by intersecting the store ids from
// their replicas.
if !replicaSetsEqual(subsumedDesc.GetReplicas(), desc.GetReplicas()) {
return reply, util.Error("The two ranges replicas are not collocate")
return reply, util.Errorf("The two ranges replicas are not collocate")
}

// Init updated version of existing range descriptor.
Expand Down
2 changes: 1 addition & 1 deletion ts/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (ds *dataSpan) addData(data *proto.InternalTimeSeriesData) error {
if len(ds.datas) > 0 {
last := ds.datas[len(ds.datas)-1]
if rd.offsetAt(0) <= last.offsetAt(len(last.Samples)-1) {
return util.Error("data must be added to dataSpan in chronological order")
return util.Errorf("data must be added to dataSpan in chronological order")
}
}

Expand Down
4 changes: 2 additions & 2 deletions util/encoding/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func floatMandE(b []byte, f float64) (int, []byte) {
if len(b) < 4 {
// The formatted float must be at least 4 bytes ("1e+0") or something
// unexpected has occurred.
panic(fmt.Errorf("malformed float: %v -> %s", f, b))
panic(fmt.Sprintf("malformed float: %v -> %s", f, b))
}

// Parse the exponent.
Expand All @@ -172,7 +172,7 @@ func floatMandE(b []byte, f float64) (int, []byte) {
e10 = -e10
case '+':
default:
panic(fmt.Errorf("malformed float: %v -> %s", f, b))
panic(fmt.Sprintf("malformed float: %v -> %s", f, b))
}

// Strip off the exponent.
Expand Down
Loading

0 comments on commit a41b734

Please sign in to comment.