Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove DebugMode option. #3441

Merged
merged 12 commits into from
May 31, 2019
17 changes: 9 additions & 8 deletions chunker/json/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/dgraph-io/dgraph/types"
"github.com/dgraph-io/dgraph/types/facets"
"github.com/dgraph-io/dgraph/x"
"github.com/pkg/errors"
geom "github.com/twpayne/go-geom"
"github.com/twpayne/go-geom/encoding/geojson"
)
Expand Down Expand Up @@ -87,7 +88,7 @@ func parseFacets(m map[string]interface{}, prefix string) ([]*api.Facet, error)
jsonValue = v
valueType = api.Facet_BOOL
default:
return nil, x.Errorf("Facet value for key: %s can only be string/float64/bool.",
return nil, errors.Errorf("Facet value for key: %s can only be string/float64/bool.",
fname)
}

Expand Down Expand Up @@ -153,7 +154,7 @@ func handleBasicType(k string, v interface{}, op int, nq *api.NQuad) error {
nq.ObjectValue = &api.Value{Val: &api.Value_BoolVal{BoolVal: v}}

default:
return x.Errorf("Unexpected type for val for attr: %s while converting to nquad", k)
return errors.Errorf("Unexpected type for val for attr: %s while converting to nquad", k)
}
return nil

Expand All @@ -176,7 +177,7 @@ func handleGeoType(val map[string]interface{}, nq *api.NQuad) (bool, error) {
if len(val) == 2 && hasType && hasCoordinates {
b, err := json.Marshal(val)
if err != nil {
return false, x.Errorf("Error while trying to parse value: %+v as geo val", val)
return false, errors.Errorf("Error while trying to parse value: %+v as geo val", val)
}
ok, err := tryParseAsGeo(b, nq)
if err != nil && ok {
Expand All @@ -195,7 +196,7 @@ func tryParseAsGeo(b []byte, nq *api.NQuad) (bool, error) {
if err == nil {
geo, err := types.ObjectValue(types.GeoID, g)
if err != nil {
return false, x.Errorf("Couldn't convert value: %s to geo type", string(b))
return false, errors.Errorf("Couldn't convert value: %s to geo type", string(b))
}

nq.ObjectValue = geo
Expand Down Expand Up @@ -238,7 +239,7 @@ func mapToNquads(m map[string]interface{}, idx *int, op int, parentPred string)
if len(mr.uid) == 0 {
if op == DeleteNquads {
// Delete operations with a non-nil value must have a uid specified.
return mr, x.Errorf("UID must be present and non-zero while deleting edges.")
return mr, errors.Errorf("UID must be present and non-zero while deleting edges.")
}

mr.uid = fmt.Sprintf("_:blank-%d", *idx)
Expand Down Expand Up @@ -358,11 +359,11 @@ func mapToNquads(m map[string]interface{}, idx *int, op int, parentPred string)
mr.nquads = append(mr.nquads, cr.nquads...)
default:
return mr,
x.Errorf("Got unsupported type for list: %s", pred)
errors.Errorf("Got unsupported type for list: %s", pred)
}
}
default:
return mr, x.Errorf("Unexpected type for val for attr: %s while converting to nquad", pred)
return mr, errors.Errorf("Unexpected type for val for attr: %s while converting to nquad", pred)
}
}

Expand Down Expand Up @@ -401,7 +402,7 @@ func Parse(b []byte, op int) ([]*api.NQuad, error) {
if len(list) > 0 {
for _, obj := range list {
if _, ok := obj.(map[string]interface{}); !ok {
return nil, x.Errorf("Only array of map allowed at root.")
return nil, errors.Errorf("Only array of map allowed at root.")
}
mr, err := mapToNquads(obj.(map[string]interface{}), &idx, op, "")
if err != nil {
Expand Down
50 changes: 25 additions & 25 deletions chunker/rdf/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package rdf

import (
"errors"
"strconv"
"strings"
"unicode"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/dgraph-io/dgraph/types"
"github.com/dgraph-io/dgraph/types/facets"
"github.com/dgraph-io/dgraph/x"
"github.com/pkg/errors"
)

var (
Expand Down Expand Up @@ -80,11 +80,11 @@ L:
case itemVarKeyword:
it.Next()
if item = it.Item(); item.Typ != itemLeftRound {
return rnq, x.Errorf("Expected '(', found: %s", item.Val)
return rnq, errors.Errorf("Expected '(', found: %s", item.Val)
}
it.Next()
if item = it.Item(); item.Typ != itemVarName {
return rnq, x.Errorf("Expected variable name, found: %s", item.Val)
return rnq, errors.Errorf("Expected variable name, found: %s", item.Val)
}

it.Next() // parse ')'
Expand All @@ -109,7 +109,7 @@ L:
var err error
oval, err = strconv.Unquote(item.Val)
if err != nil {
return rnq, x.Wrapf(err, "while unquoting")
return rnq, errors.Wrapf(err, "while unquoting")
}
seenOval = true

Expand All @@ -118,21 +118,21 @@ L:

case itemObjectType:
if rnq.Predicate == x.Star || rnq.Subject == x.Star {
return rnq, x.Errorf("If predicate/subject is *, value should be * as well")
return rnq, errors.Errorf("If predicate/subject is *, value should be * as well")
}

val := strings.Trim(item.Val, " ")
// TODO: Check if this condition is required.
if strings.Trim(val, " ") == "*" {
return rnq, x.Errorf("itemObject can't be *")
return rnq, errors.Errorf("itemObject can't be *")
}
// Lets find out the storage type from the type map.
t, ok := typeMap[val]
if !ok {
return rnq, x.Errorf("Unrecognized rdf type %s", val)
return rnq, errors.Errorf("Unrecognized rdf type %s", val)
}
if oval == "" && t != types.StringID {
return rnq, x.Errorf("Invalid ObjectValue")
return rnq, errors.Errorf("Invalid ObjectValue")
}
src := types.ValueForType(types.StringID)
src.Value = []byte(oval)
Expand All @@ -155,13 +155,13 @@ L:
case itemValidEnd:
vend = true
if !it.Next() {
return rnq, x.Errorf("Invalid end of input. Input: [%s]", line)
return rnq, errors.Errorf("Invalid end of input. Input: [%s]", line)
}
// RDF spec says N-Quads should be terminated with a newline. Since we break the input
// by newline already. We should get EOF or # after dot(.)
item = it.Item()
if !(item.Typ == lex.ItemEOF || item.Typ == itemComment) {
return rnq, x.Errorf("Invalid end of input. Expected newline or # after ."+
return rnq, errors.Errorf("Invalid end of input. Expected newline or # after ."+
" Input: [%s]", line)
}
break L
Expand All @@ -172,13 +172,13 @@ L:
case itemLeftRound:
it.Prev() // backup '('
if err := parseFacets(it, &rnq); err != nil {
return rnq, x.Errorf(err.Error())
return rnq, errors.Errorf(err.Error())
}
}
}

if !vend {
return rnq, x.Errorf("Invalid end of input. Input: [%s]", line)
return rnq, errors.Errorf("Invalid end of input. Input: [%s]", line)
}
if isCommentLine {
return rnq, ErrEmpty
Expand All @@ -189,49 +189,49 @@ L:
rnq.ObjectValue = &api.Value{Val: &api.Value_DefaultVal{DefaultVal: oval}}
}
if len(rnq.Subject) == 0 || len(rnq.Predicate) == 0 {
return rnq, x.Errorf("Empty required fields in NQuad. Input: [%s]", line)
return rnq, errors.Errorf("Empty required fields in NQuad. Input: [%s]", line)
}
if len(rnq.ObjectId) == 0 && rnq.ObjectValue == nil {
return rnq, x.Errorf("No Object in NQuad. Input: [%s]", line)
return rnq, errors.Errorf("No Object in NQuad. Input: [%s]", line)
}
if !sane(rnq.Subject) || !sane(rnq.Predicate) ||
!sane(rnq.ObjectId) || !sane(rnq.Label) {
return rnq, x.Errorf("NQuad failed sanity check:%+v", rnq)
return rnq, errors.Errorf("NQuad failed sanity check:%+v", rnq)
}

return rnq, nil
}

func parseFacets(it *lex.ItemIterator, rnq *api.NQuad) error {
if !it.Next() {
return x.Errorf("Unexpected end of facets.")
return errors.Errorf("Unexpected end of facets.")
}
item := it.Item()
if item.Typ != itemLeftRound {
return x.Errorf("Expected '(' but found %v at Facet.", item.Val)
return errors.Errorf("Expected '(' but found %v at Facet.", item.Val)
}

for it.Next() { // parse one key value pair
// parse key
item = it.Item()
if item.Typ != itemText {
return x.Errorf("Expected key but found %v.", item.Val)
return errors.Errorf("Expected key but found %v.", item.Val)
}
facetKey := strings.TrimSpace(item.Val)
if len(facetKey) == 0 {
return x.Errorf("Empty facetKeys not allowed.")
return errors.Errorf("Empty facetKeys not allowed.")
}
// parse =
if !it.Next() {
return x.Errorf("Unexpected end of facets.")
return errors.Errorf("Unexpected end of facets.")
}
item = it.Item()
if item.Typ != itemEqual {
return x.Errorf("Expected = after facetKey. Found %v", item.Val)
return errors.Errorf("Expected = after facetKey. Found %v", item.Val)
}
// parse value or empty value
if !it.Next() {
return x.Errorf("Unexpected end of facets.")
return errors.Errorf("Unexpected end of facets.")
}
item = it.Item()
facetVal := ""
Expand All @@ -252,11 +252,11 @@ func parseFacets(it *lex.ItemIterator, rnq *api.NQuad) error {
continue
}
if item.Typ != itemText {
return x.Errorf("Expected , or ) or text but found %s", item.Val)
return errors.Errorf("Expected , or ) or text but found %s", item.Val)
}
// value was present..
if !it.Next() { // get either ')' or ','
return x.Errorf("Unexpected end of facets.")
return errors.Errorf("Unexpected end of facets.")
}
item = it.Item()
if item.Typ == itemRightRound {
Expand All @@ -265,7 +265,7 @@ func parseFacets(it *lex.ItemIterator, rnq *api.NQuad) error {
if item.Typ == itemComma {
continue
}
return x.Errorf("Expected , or ) after facet. Received %s", item.Val)
return errors.Errorf("Expected , or ) after facet. Received %s", item.Val)
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"os/user"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -150,7 +151,7 @@ func initService(basename string, idx, grpcPort int) Service {
if opts.UserOwnership {
user, err := user.Current()
if err != nil {
x.CheckfNoTrace(x.Errorf("unable to get current user: %v", err))
x.CheckfNoTrace(errors.Errorf("unable to get current user: %v", err))
}
svc.User = fmt.Sprintf("${UID:-%s}", user.Uid)
svc.WorkingDir = fmt.Sprintf("/working/%s", svc.name)
Expand Down
10 changes: 5 additions & 5 deletions conn/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package conn
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"log"
"math/rand"
Expand All @@ -34,6 +33,7 @@ import (
"github.com/dgraph-io/dgraph/raftwal"
"github.com/dgraph-io/dgraph/x"
"github.com/golang/glog"
"github.com/pkg/errors"
"go.etcd.io/etcd/raft"
"go.etcd.io/etcd/raft/raftpb"
otrace "go.opencensus.io/trace"
Expand All @@ -42,7 +42,7 @@ import (

var (
// ErrNoNode is returned when no node has been set up.
ErrNoNode = x.Errorf("No node has been set up yet")
ErrNoNode = errors.Errorf("No node has been set up yet")
)

// Node represents a node participating in the RAFT protocol.
Expand Down Expand Up @@ -444,7 +444,7 @@ func (n *Node) streamMessages(to uint64, s *stream) {
func (n *Node) doSendMessage(to uint64, msgCh chan []byte) error {
addr, has := n.Peer(to)
if !has {
return x.Errorf("Do not have address of peer %#x", to)
return errors.Errorf("Do not have address of peer %#x", to)
}
pool, err := GetPools().Get(addr)
if err != nil {
Expand Down Expand Up @@ -610,7 +610,7 @@ func (n *Node) ProposePeerRemoval(ctx context.Context, id uint64) error {
return ErrNoNode
}
if _, ok := n.Peer(id); !ok && id != n.RaftContext.Id {
return x.Errorf("Node %#x not part of group", id)
return errors.Errorf("Node %#x not part of group", id)
}
cc := raftpb.ConfChange{
Type: raftpb.ConfChangeRemoveNode,
Expand All @@ -628,7 +628,7 @@ type linReadReq struct {
indexCh chan<- uint64
}

var errReadIndex = x.Errorf("Cannot get linearized read (time expired or no configured leader)")
var errReadIndex = errors.Errorf("Cannot get linearized read (time expired or no configured leader)")
martinmr marked this conversation as resolved.
Show resolved Hide resolved

// WaitLinearizableRead waits until a linearizable read can be performed.
func (n *Node) WaitLinearizableRead(ctx context.Context) error {
Expand Down
11 changes: 6 additions & 5 deletions conn/raft_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/x"
"github.com/golang/glog"
"github.com/pkg/errors"
"go.etcd.io/etcd/raft/raftpb"
otrace "go.opencensus.io/trace"
)
Expand Down Expand Up @@ -173,18 +174,18 @@ func (w *RaftServer) JoinCluster(ctx context.Context,

// Check that the new node is from the same group as me.
if rc.Group != node.RaftContext.Group {
return nil, x.Errorf("Raft group mismatch")
return nil, errors.Errorf("Raft group mismatch")
}
// Also check that the new node is not me.
if rc.Id == node.RaftContext.Id {
return nil, x.Errorf("REUSE_RAFTID: Raft ID duplicates mine: %+v", rc)
return nil, errors.Errorf("REUSE_RAFTID: Raft ID duplicates mine: %+v", rc)
}

// Check that the new node is not already part of the group.
if addr, ok := node.Peer(rc.Id); ok && rc.Addr != addr {
// There exists a healthy connection to server with same id.
if _, err := GetPools().Get(addr); err == nil {
return &api.Payload{}, x.Errorf(
return &api.Payload{}, errors.Errorf(
"REUSE_ADDR: IP Address same as existing peer: %s", addr)
}
}
Expand Down Expand Up @@ -223,7 +224,7 @@ func (w *RaftServer) RaftMessage(server pb.Raft_RaftMessageServer) error {
idx += 4
msg := raftpb.Message{}
if idx+sz > len(data) {
return x.Errorf(
return errors.Errorf(
"Invalid query. Specified size %v overflows slice [%v,%v)\n",
sz, idx, len(data))
}
Expand All @@ -248,7 +249,7 @@ func (w *RaftServer) RaftMessage(server pb.Raft_RaftMessageServer) error {
if err := raft.Step(ctx, msg); err != nil {
glog.Warningf("Error while raft.Step from %#x: %v. Closing RaftMessage stream.",
rc.GetId(), err)
return x.Errorf("Error while raft.Step from %#x: %v", rc.GetId(), err)
return errors.Errorf("Error while raft.Step from %#x: %v", rc.GetId(), err)
}
idx += sz
}
Expand Down
3 changes: 2 additions & 1 deletion dgraph/cmd/alpha/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (

"github.com/golang/glog"
"github.com/golang/protobuf/jsonpb"
"github.com/pkg/errors"

"google.golang.org/grpc/metadata"
)
Expand All @@ -61,7 +62,7 @@ func extractStartTs(urlPath string) (uint64, error) {
}
return ts, nil
default:
return 0, x.Errorf("Incorrect no. of path parameters. Expected 1 or 2. Got: %+v", l)
return 0, errors.Errorf("Incorrect no. of path parameters. Expected 1 or 2. Got: %+v", l)
}
}

Expand Down
Loading