diff --git a/core/crdt/lwwreg.go b/core/crdt/lwwreg.go index 6a39527788..748959a28b 100644 --- a/core/crdt/lwwreg.go +++ b/core/crdt/lwwreg.go @@ -13,8 +13,9 @@ import ( // "time" "bytes" + "fmt" - "github.com/pkg/errors" + "errors" "github.com/sourcenetwork/defradb/core" @@ -135,7 +136,7 @@ func (reg LWWRegister) Merge(delta core.Delta, id string) error { func (reg LWWRegister) setValue(val []byte, priority uint64) error { curPrio, err := reg.getPriority(reg.key) if err != nil { - return errors.Wrap(err, "Failed to get priority for Set") + return fmt.Errorf("Failed to get priority for Set : %w", err) } // if the current priority is higher ignore put @@ -155,7 +156,7 @@ func (reg LWWRegister) setValue(val []byte, priority uint64) error { buf := append([]byte{byte(core.LWW_REGISTER)}, val...) err = reg.store.Put(valueK, buf) if err != nil { - return errors.Wrap(err, "Failed to store new value") + return fmt.Errorf("Failed to store new value : %w", err) } return reg.setPriority(reg.key, priority) diff --git a/core/key.go b/core/key.go index 5fed907ba6..5a1c11d933 100644 --- a/core/key.go +++ b/core/key.go @@ -10,10 +10,10 @@ package core import ( + "fmt" "strconv" ds "github.com/ipfs/go-datastore" - "github.com/pkg/errors" ) var ( @@ -62,7 +62,7 @@ func (k Key) FieldID() (uint32, error) { fieldIDStr := k.Type() fieldID, err := strconv.Atoi(fieldIDStr) if err != nil { - return 0, errors.Wrap(err, "Failed to get FieldID of Key") + return 0, fmt.Errorf("Failed to get FieldID of Key: %w", err) } return uint32(fieldID), nil } diff --git a/db/collection.go b/db/collection.go index 8d8f571d69..de3ecea7e1 100644 --- a/db/collection.go +++ b/db/collection.go @@ -21,11 +21,12 @@ import ( "github.com/sourcenetwork/defradb/document/key" "github.com/sourcenetwork/defradb/merkle/crdt" + "errors" + "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/query" mh "github.com/multiformats/go-multihash" - "github.com/pkg/errors" ) var ( @@ -306,7 +307,7 @@ func (c *Collection) create(txn *Txn, doc *document.Document) error { // fmt.Println(c) dockey := key.NewDocKeyV0(doccid) if !dockey.Key.Equal(doc.Key().Key) { - return errors.Wrap(ErrDocVerification, fmt.Sprintf("Expected %s, got %s", doc.Key().UUID(), dockey.UUID())) + return fmt.Errorf("Expected %s, got %s : %w", doc.Key().UUID(), dockey.UUID(), ErrDocVerification) } // check if doc already exists diff --git a/db/collection_update.go b/db/collection_update.go index 70ebf4c12a..e0bf7ee016 100644 --- a/db/collection_update.go +++ b/db/collection_update.go @@ -11,6 +11,7 @@ package db import ( "encoding/json" + "errors" "fmt" "strings" "time" @@ -25,7 +26,6 @@ import ( "github.com/fxamacker/cbor/v2" ds "github.com/ipfs/go-datastore" - "github.com/pkg/errors" ) type UpdateOpt struct{} diff --git a/db/db.go b/db/db.go index d9a0af2c8a..c12cd6bd9e 100644 --- a/db/db.go +++ b/db/db.go @@ -10,11 +10,10 @@ package db import ( + "errors" "fmt" "sync" - "github.com/pkg/errors" - "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/core" "github.com/sourcenetwork/defradb/merkle/crdt" diff --git a/db/fetcher/dag.go b/db/fetcher/dag.go index 897f76fd5b..ba641aee46 100644 --- a/db/fetcher/dag.go +++ b/db/fetcher/dag.go @@ -156,13 +156,13 @@ func (hh *heads) List() ([]cid.Cid, uint64, error) { var maxHeight uint64 for r := range results.Next() { if r.Error != nil { - return nil, 0, errors.Wrap(r.Error, "Failed to get next query result") + return nil, 0, fmt.Errorf("Failed to get next query result : %w", err) } // fmt.Println(r.Key, hh.namespace.String()) headKey := ds.NewKey(strings.TrimPrefix(r.Key, hh.namespace.String())) headCid, err := dshelp.DsKeyToCid(headKey) if err != nil { - return nil, 0, errors.Wrap(err, "Failed to get CID from key") + return nil, 0, fmt.Errorf("Failed to get CID from key : %w", err) } height, n := binary.Uvarint(r.Value) if n <= 0 { diff --git a/db/sequence.go b/db/sequence.go index 0b95d02668..b1e2a0f03d 100644 --- a/db/sequence.go +++ b/db/sequence.go @@ -12,8 +12,9 @@ package db import ( "encoding/binary" + "errors" + ds "github.com/ipfs/go-datastore" - "github.com/pkg/errors" ) type sequence struct { diff --git a/merkle/clock/clock.go b/merkle/clock/clock.go index fa2a50787e..fcfd62c3ba 100644 --- a/merkle/clock/clock.go +++ b/merkle/clock/clock.go @@ -10,7 +10,7 @@ package clock import ( - "github.com/pkg/errors" + "fmt" "github.com/sourcenetwork/defradb/core" @@ -52,7 +52,7 @@ func (mc *MerkleClock) putBlock(heads []cid.Cid, height uint64, delta core.Delta node, err := makeNode(delta, heads) if err != nil { - return nil, errors.Wrap(err, "error creating block") + return nil, fmt.Errorf("error creating block : %w", err) } // @todo Add a DagSyncer instance to the MerkleCRDT structure @@ -63,11 +63,11 @@ func (mc *MerkleClock) putBlock(heads []cid.Cid, height uint64, delta core.Delta // ctx := context.Background() // err = mc.store.dagSyncer.Add(ctx, node) // if err != nil { - // return nil, errors.Wrapf(err, "error writing new block %s", node.Cid()) + // return nil, fmt.Errorf("error writing new block %s : %w", node.Cid(), err) // } err = mc.dagstore.Put(node) if err != nil { - return nil, errors.Wrapf(err, "error writing new block %s", node.Cid()) + return nil, fmt.Errorf("error writing new block %s : %w", node.Cid(), err) } return node, nil @@ -81,7 +81,7 @@ func (mc *MerkleClock) putBlock(heads []cid.Cid, height uint64, delta core.Delta func (mc *MerkleClock) AddDAGNode(delta core.Delta) (cid.Cid, error) { heads, height, err := mc.headset.List() if err != nil { - return cid.Undef, errors.Wrap(err, "error getting heads") + return cid.Undef, fmt.Errorf("error getting heads : %w", err) } height = height + 1 @@ -90,7 +90,7 @@ func (mc *MerkleClock) AddDAGNode(delta core.Delta) (cid.Cid, error) { // write the delta and heads to a new block nd, err := mc.putBlock(heads, height, delta) if err != nil { - return cid.Undef, errors.Wrap(err, "Error adding block") + return cid.Undef, fmt.Errorf("Error adding block : %w", err) } // apply the new node and merge the delta with state @@ -104,7 +104,7 @@ func (mc *MerkleClock) AddDAGNode(delta core.Delta) (cid.Cid, error) { ) if err != nil { - return cid.Undef, errors.Wrap(err, "error processing new block") + return cid.Undef, fmt.Errorf("error processing new block : %w", err) } return nd.Cid(), nil } @@ -115,7 +115,7 @@ func (mc *MerkleClock) ProcessNode(ng core.NodeGetter, root cid.Cid, rootPrio ui current := node.Cid() err := mc.crdt.Merge(delta, dshelp.CidToDsKey(current).String()) if err != nil { - return nil, errors.Wrapf(err, "error merging delta from %s", current) + return nil, fmt.Errorf("error merging delta from %s : %w", current, err) } // if prio := delta.GetPriority(); prio%10 == 0 { @@ -136,7 +136,7 @@ func (mc *MerkleClock) ProcessNode(ng core.NodeGetter, root cid.Cid, rootPrio ui if !hasHeads { // reached the bottom, at a leaf err := mc.headset.Add(root, rootPrio) if err != nil { - return nil, errors.Wrapf(err, "error adding head %s", root) + return nil, fmt.Errorf("error adding head %s : %w", root, err) } return nil, nil } @@ -147,7 +147,7 @@ func (mc *MerkleClock) ProcessNode(ng core.NodeGetter, root cid.Cid, rootPrio ui child := l.Cid isHead, _, err := mc.headset.IsHead(child) if err != nil { - return nil, errors.Wrapf(err, "error checking if %s is head", child) + return nil, fmt.Errorf("error checking if %s is head : %w", child, err) } if isHead { @@ -155,7 +155,7 @@ func (mc *MerkleClock) ProcessNode(ng core.NodeGetter, root cid.Cid, rootPrio ui // of current branch err := mc.headset.Replace(child, root, rootPrio) if err != nil { - return nil, errors.Wrapf(err, "error replacing head: %s->%s", child, root) + return nil, fmt.Errorf("error replacing head: %s->%s : %w", child, root, err) } continue @@ -163,7 +163,7 @@ func (mc *MerkleClock) ProcessNode(ng core.NodeGetter, root cid.Cid, rootPrio ui known, err := mc.dagstore.Has(child) if err != nil { - return nil, errors.Wrapf(err, "error checking for know block %s", child) + return nil, fmt.Errorf("error checking for know block %s : %w", child, err) } if known { // we reached a non-head node in the known tree. diff --git a/merkle/clock/heads.go b/merkle/clock/heads.go index 1b5128c6a6..b727e2b874 100644 --- a/merkle/clock/heads.go +++ b/merkle/clock/heads.go @@ -12,10 +12,12 @@ package clock import ( "bytes" "encoding/binary" + "fmt" "sort" "strings" - "github.com/pkg/errors" + "errors" + "github.com/sourcenetwork/defradb/core" cid "github.com/ipfs/go-cid" @@ -141,13 +143,13 @@ func (hh *heads) List() ([]cid.Cid, uint64, error) { var maxHeight uint64 for r := range results.Next() { if r.Error != nil { - return nil, 0, errors.Wrap(r.Error, "Failed to get next query result") + return nil, 0, fmt.Errorf("Failed to get next query result : %w", r.Error) } // fmt.Println(r.Key, hh.namespace.String()) headKey := ds.NewKey(strings.TrimPrefix(r.Key, hh.namespace.String())) headCid, err := dshelp.DsKeyToCid(headKey) if err != nil { - return nil, 0, errors.Wrap(err, "Failed to get CID from key") + return nil, 0, fmt.Errorf("Failed to get CID from key : %w", err) } height, n := binary.Uvarint(r.Value) if n <= 0 { diff --git a/merkle/crdt/merklecrdt.go b/merkle/crdt/merklecrdt.go index 8436d7e93e..a22765df3b 100644 --- a/merkle/crdt/merklecrdt.go +++ b/merkle/crdt/merklecrdt.go @@ -76,7 +76,7 @@ func (base *baseMerkleCRDT) Value() ([]byte, error) { // current := node.Cid() // err := base.Merge(delta, dshelp.CidToDsKey(current).String()) // if err != nil { -// return nil, errors.Wrapf(eff, "error merging delta from %s", current) +// return nil, fmt.Errorf("error merging delta from %s : %w", current, err) // } // return base.clock.ProcessNode(ng, root, rootPrio, delta, node) diff --git a/query/graphql/planner/dagscan.go b/query/graphql/planner/dagscan.go index 9abd28d572..545393c0cc 100644 --- a/query/graphql/planner/dagscan.go +++ b/query/graphql/planner/dagscan.go @@ -11,10 +11,9 @@ package planner import ( "container/list" + "errors" "strings" - // "errors" - "github.com/sourcenetwork/defradb/core" "github.com/sourcenetwork/defradb/db/fetcher" @@ -23,7 +22,6 @@ import ( cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" dag "github.com/ipfs/go-merkledag" - "github.com/pkg/errors" ) type headsetScanNode struct { diff --git a/query/graphql/planner/planner.go b/query/graphql/planner/planner.go index ad7a3140f9..af75b3511d 100644 --- a/query/graphql/planner/planner.go +++ b/query/graphql/planner/planner.go @@ -14,7 +14,8 @@ import ( "fmt" "reflect" - "github.com/pkg/errors" + "errors" + "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/core" "github.com/sourcenetwork/defradb/query/graphql/parser" @@ -130,7 +131,7 @@ func (p *Planner) newPlan(stmt parser.Statement) (planNode, error) { case *parser.Mutation: return p.newObjectMutationPlan(n) } - return nil, errors.Errorf("unknown statement type %T", stmt) + return nil, fmt.Errorf("unknown statement type %T", stmt) } func (p *Planner) newObjectMutationPlan(stmt *parser.Mutation) (planNode, error) { @@ -140,7 +141,7 @@ func (p *Planner) newObjectMutationPlan(stmt *parser.Mutation) (planNode, error) case parser.UpdateObjects: return p.UpdateDocs(stmt) default: - return nil, errors.Errorf("unknown mutation action %T", stmt.Type) + return nil, fmt.Errorf("unknown mutation action %T", stmt.Type) } } diff --git a/query/graphql/schema/generate_test.go b/query/graphql/schema/generate_test.go index 21153be436..f10461b103 100644 --- a/query/graphql/schema/generate_test.go +++ b/query/graphql/schema/generate_test.go @@ -10,12 +10,12 @@ package schema import ( + "errors" "fmt" "reflect" "strings" "testing" - "github.com/pkg/errors" "github.com/sourcenetwork/defradb/query/graphql/schema/types" "github.com/davecgh/go-spew/spew" @@ -479,14 +479,14 @@ func runTestConfigForbuildTypesFromASTSuite(t *testing.T, schema string, typeDef // Source: source, // }) // if err != nil { - // return errors.Wrap(err, "Failed to parse schema string") + // return fmt.Errorf("Failed to parse schema string : %w", err) // } // // assert.NoError(t, err, "Failed to parse schema string") // err = g.buildTypesFromAST(doc) _, _, err := g.FromSDL(schema) if err != nil { - return errors.Wrap(err, "Failed to build types from AST") + return fmt.Errorf("Failed to build types from AST : %w", err) } // assert.NoError(t, err, "Failed to build types from AST") @@ -497,7 +497,7 @@ func runTestConfigForbuildTypesFromASTSuite(t *testing.T, schema string, typeDef return errors.New(fmt.Sprintf("%s type doesn't exist in the schema manager TypeMap", objName)) } if myObject.Error() != nil { - return errors.Wrapf(myObject.Error(), "%s contains an internal error", objName) + return fmt.Errorf("%s contains an internal error : %w", objName, myObject.Error()) } if !reflect.DeepEqual(myObject, g.typeDefs[i]) { // add the assert here for its object diff output @@ -511,7 +511,7 @@ func runTestConfigForbuildTypesFromASTSuite(t *testing.T, schema string, typeDef // to resolve the FieldsThunker if myObject.Error() != nil { - return errors.Wrap(myObject.Error(), fmt.Sprintf("%s contains an internal error from the Fields() > definFields() call", objName)) + return fmt.Errorf("%s contains an internal error from the Fields() > definFields() call : %w", objName, myObject.Error()) } // assert.NoErrorf(t, myObjectActual.Error(), "%s contains an internal error from the defineFields() call", objName)