From 0ff3bba9641c9dafc9d7d25d2826fabdd133e66b Mon Sep 17 00:00:00 2001 From: Fred Carle Date: Sun, 16 Oct 2022 19:13:56 -0400 Subject: [PATCH 1/3] add error-strings rule --- mapper/mapper.go | 2 +- planner/planner.go | 4 ++-- planner/type_join.go | 2 +- tools/configs/golangci.yaml | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mapper/mapper.go b/mapper/mapper.go index eeb91a0615..9591dc8895 100644 --- a/mapper/mapper.go +++ b/mapper/mapper.go @@ -525,7 +525,7 @@ func getAggregateRequests(index int, aggregate *parser.Select) (aggregateRequest if len(aggregateTargets) == 0 { return aggregateRequest{}, errors.New( - "Aggregate must be provided with a property to aggregate.", + "aggregate must be provided with a property to aggregate", ) } diff --git a/planner/planner.go b/planner/planner.go index 3e677698de..6d280c4061 100644 --- a/planner/planner.go +++ b/planner/planner.go @@ -449,7 +449,7 @@ func (p *Planner) explainRequest( plan planNode, ) ([]map[string]any, error) { if plan == nil { - return nil, errors.New("Can't explain request of a nil plan.") + return nil, errors.New("can't explain request of a nil plan") } explainGraph, err := buildExplainGraph(plan) @@ -472,7 +472,7 @@ func (p *Planner) executeRequest( plan planNode, ) ([]map[string]any, error) { if plan == nil { - return nil, errors.New("Can't execute request of a nil plan.") + return nil, errors.New("can't execute request of a nil plan") } if err := plan.Start(); err != nil { diff --git a/planner/type_join.go b/planner/type_join.go index b6ad2c6aac..511ad8525e 100644 --- a/planner/type_join.go +++ b/planner/type_join.go @@ -185,7 +185,7 @@ func (n *typeIndexJoin) Explain() (map[string]any, error) { explainerMap[joinSubTypeLabel] = subTypeExplainGraph default: - return explainerMap, errors.New("Unknown type of an index join to explain.") + return explainerMap, errors.New("unknown type of an index join to explain") } return explainerMap, nil diff --git a/tools/configs/golangci.yaml b/tools/configs/golangci.yaml index 59de3580a2..020b0ea913 100644 --- a/tools/configs/golangci.yaml +++ b/tools/configs/golangci.yaml @@ -331,6 +331,8 @@ linters-settings: severity: error - name: use-any severity: error + - name: error-strings + severity: error staticcheck: # Select the Go version to target. From 3498e8a7e92b10507e4b2cf261d875bc52ecb25a Mon Sep 17 00:00:00 2001 From: Fred Carle Date: Sun, 16 Oct 2022 19:25:10 -0400 Subject: [PATCH 2/3] fix tests --- tests/integration/query/simple/with_average_test.go | 2 +- tests/integration/query/simple/with_count_test.go | 2 +- tests/integration/query/simple/with_group_average_test.go | 2 +- tests/integration/query/simple/with_group_count_test.go | 2 +- tests/integration/query/simple/with_group_sum_test.go | 2 +- tests/integration/query/simple/with_sum_test.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration/query/simple/with_average_test.go b/tests/integration/query/simple/with_average_test.go index a2c7fe1532..5135d69c4b 100644 --- a/tests/integration/query/simple/with_average_test.go +++ b/tests/integration/query/simple/with_average_test.go @@ -22,7 +22,7 @@ func TestQuerySimpleWithAverageOnUndefinedObject(t *testing.T) { Query: `query { _avg }`, - ExpectedError: "Aggregate must be provided with a property to aggregate.", + ExpectedError: "aggregate must be provided with a property to aggregate", } executeTestCase(t, test) diff --git a/tests/integration/query/simple/with_count_test.go b/tests/integration/query/simple/with_count_test.go index d466941b64..af2cb6946d 100644 --- a/tests/integration/query/simple/with_count_test.go +++ b/tests/integration/query/simple/with_count_test.go @@ -22,7 +22,7 @@ func TestQuerySimpleWithCountOnUndefined(t *testing.T) { Query: `query { _count }`, - ExpectedError: "Aggregate must be provided with a property to aggregate.", + ExpectedError: "aggregate must be provided with a property to aggregate", } executeTestCase(t, test) diff --git a/tests/integration/query/simple/with_group_average_test.go b/tests/integration/query/simple/with_group_average_test.go index 697bd5d7e3..d7b10a5718 100644 --- a/tests/integration/query/simple/with_group_average_test.go +++ b/tests/integration/query/simple/with_group_average_test.go @@ -33,7 +33,7 @@ func TestQuerySimpleWithGroupByStringWithoutRenderedGroupAndAverageOfUndefined(t }`, }, }, - ExpectedError: "Aggregate must be provided with a property to aggregate.", + ExpectedError: "aggregate must be provided with a property to aggregate", } executeTestCase(t, test) diff --git a/tests/integration/query/simple/with_group_count_test.go b/tests/integration/query/simple/with_group_count_test.go index cacfbeb6e9..f33ae6c3b5 100644 --- a/tests/integration/query/simple/with_group_count_test.go +++ b/tests/integration/query/simple/with_group_count_test.go @@ -201,7 +201,7 @@ func TestQuerySimpleWithGroupByNumberWithUndefinedField(t *testing.T) { }`, }, }, - ExpectedError: "Aggregate must be provided with a property to aggregate.", + ExpectedError: "aggregate must be provided with a property to aggregate", } executeTestCase(t, test) diff --git a/tests/integration/query/simple/with_group_sum_test.go b/tests/integration/query/simple/with_group_sum_test.go index 2608dec26e..bcecb5bf28 100644 --- a/tests/integration/query/simple/with_group_sum_test.go +++ b/tests/integration/query/simple/with_group_sum_test.go @@ -33,7 +33,7 @@ func TestQuerySimpleWithGroupByStringWithoutRenderedGroupAndSumOfUndefined(t *te }`, }, }, - ExpectedError: "Aggregate must be provided with a property to aggregate.", + ExpectedError: "aggregate must be provided with a property to aggregate", } executeTestCase(t, test) diff --git a/tests/integration/query/simple/with_sum_test.go b/tests/integration/query/simple/with_sum_test.go index 6f5862d642..2251697b14 100644 --- a/tests/integration/query/simple/with_sum_test.go +++ b/tests/integration/query/simple/with_sum_test.go @@ -22,7 +22,7 @@ func TestQuerySimpleWithSumOnUndefinedObject(t *testing.T) { Query: `query { _sum }`, - ExpectedError: "Aggregate must be provided with a property to aggregate.", + ExpectedError: "aggregate must be provided with a property to aggregate", } executeTestCase(t, test) From 28070eec7413f029242d231ada62b4da49285a03 Mon Sep 17 00:00:00 2001 From: Fred Carle Date: Wed, 19 Oct 2022 14:47:29 -0400 Subject: [PATCH 3/3] add string-format rule for revive linter --- api/http/errors_test.go | 6 ++--- client/dockey.go | 4 +-- client/document.go | 2 +- client/errors.go | 14 +++++----- core/crdt/composite.go | 2 +- core/crdt/lwwreg.go | 6 ++--- core/key.go | 2 +- core/replicated.go | 2 +- db/base/collection_keys.go | 2 +- db/collection.go | 24 ++++++++--------- db/collection_delete.go | 6 ++--- db/collection_test.go | 18 ++++++------- db/collection_update.go | 14 +++++----- db/db.go | 8 +++--- db/fetcher/dag.go | 8 +++--- db/fetcher/fetcher.go | 12 ++++----- db/fetcher/versioned.go | 6 ++--- go.mod | 3 +-- go.sum | 1 - mapper/descriptions.go | 2 +- mapper/mapper.go | 6 ++--- merkle/clock/clock.go | 2 +- merkle/clock/heads.go | 2 +- merkle/crdt/factory.go | 2 +- net/api/client/client.go | 4 +-- net/client.go | 4 +-- net/peer.go | 12 ++++----- net/process.go | 6 ++--- net/server.go | 4 +-- planner/commit.go | 2 +- planner/create.go | 2 +- planner/datasource.go | 2 +- planner/executor.go | 4 +-- planner/multi.go | 8 +++--- planner/planner.go | 8 +++--- planner/select.go | 2 +- planner/sum.go | 2 +- planner/top.go | 2 +- planner/type_join.go | 2 +- planner/versionedscan.go | 2 +- query/graphql/parser/filter.go | 10 +++---- query/graphql/parser/query.go | 6 ++--- query/graphql/schema/descriptions.go | 2 +- query/graphql/schema/generate.go | 6 ++--- query/graphql/schema/relations.go | 10 +++---- tests/bench/bench_util.go | 10 +++---- tests/bench/query/planner/utils.go | 8 +++--- .../update/simple/with_filter_test.go | 2 +- .../collection/update/simple/with_key_test.go | 2 +- .../update/simple/with_keys_test.go | 2 +- .../mutation/simple/create/simple_test.go | 2 +- .../integration/query/simple/with_cid_test.go | 2 +- tools/configs/golangci.yaml | 27 +++++++++++++++++++ 53 files changed, 167 insertions(+), 142 deletions(-) diff --git a/api/http/errors_test.go b/api/http/errors_test.go index 4d7e9a0035..9e4a5885c8 100644 --- a/api/http/errors_test.go +++ b/api/http/errors_test.go @@ -139,7 +139,7 @@ func TestHandleErrOnDefault(t *testing.T) { t.Cleanup(CleanupEnv) env = "dev" f := func(rw http.ResponseWriter, req *http.Request) { - handleErr(req.Context(), rw, errors.New("Unauthorized"), http.StatusUnauthorized) + handleErr(req.Context(), rw, errors.New("unauthorized"), http.StatusUnauthorized) } req, err := http.NewRequest("GET", "/test", nil) if err != nil { @@ -164,6 +164,6 @@ func TestHandleErrOnDefault(t *testing.T) { assert.Equal(t, http.StatusUnauthorized, errResponse.Errors[0].Extensions.Status) assert.Equal(t, http.StatusText(http.StatusUnauthorized), errResponse.Errors[0].Extensions.HTTPError) - assert.Equal(t, "Unauthorized", errResponse.Errors[0].Message) - assert.Contains(t, errResponse.Errors[0].Extensions.Stack, "[DEV] Unauthorized") + assert.Equal(t, "unauthorized", errResponse.Errors[0].Message) + assert.Contains(t, errResponse.Errors[0].Extensions.Stack, "[DEV] unauthorized") } diff --git a/client/dockey.go b/client/dockey.go index c88ae2d0f4..48ca326566 100644 --- a/client/dockey.go +++ b/client/dockey.go @@ -56,7 +56,7 @@ func NewDocKeyV0(dataCID cid.Cid) DocKey { func NewDocKeyFromString(key string) (DocKey, error) { parts := strings.SplitN(key, "-", 2) if len(parts) != 2 { - return DocKey{}, errors.New("Malformed DocKey, missing either version or cid") + return DocKey{}, errors.New("malformed DocKey, missing either version or cid") } versionStr := parts[0] _, data, err := mbase.Decode(versionStr) @@ -69,7 +69,7 @@ func NewDocKeyFromString(key string) (DocKey, error) { return DocKey{}, err } if _, ok := ValidDocKeyVersions[uint16(version)]; !ok { - return DocKey{}, errors.New("Invalid DocKey version") + return DocKey{}, errors.New("invalid DocKey version") } uuid, err := uuid.FromString(parts[1]) diff --git a/client/document.go b/client/document.go index 19b836fcf0..bd51724f68 100644 --- a/client/document.go +++ b/client/document.go @@ -89,7 +89,7 @@ func NewDocFromMap(data map[string]any) (*Document, error) { delete(data, "_key") // remove the key so it isn't parsed further kstr, ok := k.(string) if !ok { - return nil, errors.New("Provided _key in document must be a string type") + return nil, errors.New("provided _key in document must be a string type") } if doc.key, err = NewDocKeyFromString(kstr); err != nil { return nil, err diff --git a/client/errors.go b/client/errors.go index 59c2162a04..6abfed0da8 100644 --- a/client/errors.go +++ b/client/errors.go @@ -24,13 +24,13 @@ const ( var ( ErrFieldNotExist = errors.New(errFieldNotExist) ErrSelectOfNonGroupField = errors.New(errSelectOfNonGroupField) - ErrFieldNotObject = errors.New("Trying to access field on a non object type") - ErrValueTypeMismatch = errors.New("Value does not match indicated type") - ErrIndexNotFound = errors.New("No index found for given ID") - ErrDocumentNotFound = errors.New("No document for the given key exists") - ErrInvalidUpdateTarget = errors.New("The target document to update is of invalid type") - ErrInvalidUpdater = errors.New("The updater of a document is of invalid type") - ErrInvalidDeleteTarget = errors.New("The target document to delete is of invalid type") + ErrFieldNotObject = errors.New("trying to access field on a non object type") + ErrValueTypeMismatch = errors.New("value does not match indicated type") + ErrIndexNotFound = errors.New("no index found for given ID") + ErrDocumentNotFound = errors.New("no document for the given key exists") + ErrInvalidUpdateTarget = errors.New("the target document to update is of invalid type") + ErrInvalidUpdater = errors.New("the updater of a document is of invalid type") + ErrInvalidDeleteTarget = errors.New("the target document to delete is of invalid type") ) func NewErrFieldNotExist(name string) error { diff --git a/core/crdt/composite.go b/core/crdt/composite.go index d1c571f8fa..883ec855e7 100644 --- a/core/crdt/composite.go +++ b/core/crdt/composite.go @@ -135,7 +135,7 @@ func (c CompositeDAG) DeltaDecode(node ipld.Node) (core.Delta, error) { delta := &CompositeDAGDelta{} pbNode, ok := node.(*dag.ProtoNode) if !ok { - return nil, errors.New("Failed to cast ipld.Node to ProtoNode") + return nil, errors.New("failed to cast ipld.Node to ProtoNode") } data := pbNode.Data() h := &codec.CborHandle{} diff --git a/core/crdt/lwwreg.go b/core/crdt/lwwreg.go index 4b64d58f44..11f3049c5c 100644 --- a/core/crdt/lwwreg.go +++ b/core/crdt/lwwreg.go @@ -139,7 +139,7 @@ func (reg LWWRegister) Merge(ctx context.Context, delta core.Delta, id string) e func (reg LWWRegister) setValue(ctx context.Context, val []byte, priority uint64) error { curPrio, err := reg.getPriority(ctx, reg.key) if err != nil { - return errors.Wrap("Failed to get priority for Set ", err) + return errors.Wrap("failed to get priority for Set ", err) } // if the current priority is higher ignore put @@ -159,7 +159,7 @@ func (reg LWWRegister) setValue(ctx context.Context, val []byte, priority uint64 buf := append([]byte{byte(client.LWW_REGISTER)}, val...) err = reg.store.Put(ctx, valueK.ToDS(), buf) if err != nil { - return errors.Wrap("Failed to store new value ", err) + return errors.Wrap("failed to store new value ", err) } return reg.setPriority(ctx, reg.key, priority) @@ -172,7 +172,7 @@ func (reg LWWRegister) DeltaDecode(node ipld.Node) (core.Delta, error) { delta := &LWWRegDelta{} pbNode, ok := node.(*dag.ProtoNode) if !ok { - return nil, errors.New("Failed to cast ipld.Node to ProtoNode") + return nil, errors.New("failed to cast ipld.Node to ProtoNode") } data := pbNode.Data() h := &codec.CborHandle{} diff --git a/core/key.go b/core/key.go index 935fd0fea0..f28c7f1262 100644 --- a/core/key.go +++ b/core/key.go @@ -432,7 +432,7 @@ func (k DataStoreKey) PrefixEnd() DataStoreKey { func (k DataStoreKey) FieldID() (uint32, error) { fieldID, err := strconv.Atoi(k.FieldId) if err != nil { - return 0, errors.Wrap("Failed to get FieldID of Key", err) + return 0, errors.Wrap("failed to get FieldID of Key", err) } return uint32(fieldID), nil } diff --git a/core/replicated.go b/core/replicated.go index b00e59b87f..5947298395 100644 --- a/core/replicated.go +++ b/core/replicated.go @@ -21,7 +21,7 @@ import ( var ( // ErrMismatchedMergeType - Tying to merge two ReplicatedData of different types - ErrMismatchedMergeType = errors.New("Given type to merge does not match source") + ErrMismatchedMergeType = errors.New("given type to merge does not match source") ) // ReplicatedData is a data type that allows concurrent writers diff --git a/db/base/collection_keys.go b/db/base/collection_keys.go index 67467901cc..96784d5814 100644 --- a/db/base/collection_keys.go +++ b/db/base/collection_keys.go @@ -46,7 +46,7 @@ func MakePrimaryIndexKeyForCRDT( fieldKey := getFieldKey(c, key, fieldName) return MakeCollectionKey(c).WithInstanceInfo(fieldKey), nil } - return core.DataStoreKey{}, errors.New("Invalid CRDT type") + return core.DataStoreKey{}, errors.New("invalid CRDT type") } func getFieldKey( diff --git a/db/collection.go b/db/collection.go index a28b71b551..66bc4739c1 100644 --- a/db/collection.go +++ b/db/collection.go @@ -34,8 +34,8 @@ import ( ) var ( - ErrDocumentAlreadyExists = errors.New("A document with the given dockey already exists") - ErrUnknownCRDTArgument = errors.New("Invalid CRDT arguments") + ErrDocumentAlreadyExists = errors.New("a document with the given dockey already exists") + ErrUnknownCRDTArgument = errors.New("invalid CRDT arguments") ErrUnknownCRDT = errors.New("") ) @@ -63,29 +63,29 @@ type collection struct { // NewCollection returns a pointer to a newly instanciated DB Collection func (db *db) newCollection(desc client.CollectionDescription) (*collection, error) { if desc.Name == "" { - return nil, errors.New("Collection requires name to not be empty") + return nil, errors.New("collection requires name to not be empty") } if len(desc.Schema.Fields) == 0 { - return nil, errors.New("Collection schema has no fields") + return nil, errors.New("collection schema has no fields") } docKeyField := desc.Schema.Fields[0] if docKeyField.Kind != client.FieldKind_DocKey || docKeyField.Name != "_key" { - return nil, errors.New("Collection schema first field must be a DocKey") + return nil, errors.New("collection schema first field must be a DocKey") } desc.Schema.FieldIDs = make([]uint32, len(desc.Schema.Fields)) for i, field := range desc.Schema.Fields { if field.Name == "" { - return nil, errors.New("Collection schema field missing Name") + return nil, errors.New("collection schema field missing Name") } if field.Kind == client.FieldKind_None { - return nil, errors.New("Collection schema field missing FieldKind") + return nil, errors.New("collection schema field missing FieldKind") } if (field.Kind != client.FieldKind_DocKey && !field.IsObject()) && field.Typ == client.NONE_CRDT { - return nil, errors.New("Collection schema field missing CRDT type") + return nil, errors.New("collection schema field missing CRDT type") } desc.Schema.FieldIDs[i] = uint32(i) desc.Schema.Fields[i].ID = client.FieldID(i) @@ -122,7 +122,7 @@ func (db *db) CreateCollection( return nil, err } if exists { - return nil, errors.New("Collection already exists") + return nil, errors.New("collection already exists") } colSeq, err := db.getSequence(ctx, core.COLLECTION) @@ -181,7 +181,7 @@ func (db *db) CreateCollection( // GetCollection returns an existing collection within the database func (db *db) GetCollectionByName(ctx context.Context, name string) (client.Collection, error) { if name == "" { - return nil, errors.New("Collection name can't be empty") + return nil, errors.New("collection name can't be empty") } key := core.NewCollectionKey(name) @@ -233,7 +233,7 @@ func (db *db) GetCollectionBySchemaID( schemaID string, ) (client.Collection, error) { if schemaID == "" { - return nil, errors.New("Schema ID can't be empty") + return nil, errors.New("schema ID can't be empty") } key := core.NewCollectionSchemaKey(schemaID) @@ -256,7 +256,7 @@ func (db *db) GetAllCollections(ctx context.Context) ([]client.Collection, error KeysOnly: true, }) if err != nil { - return nil, errors.Wrap("Failed to create collection prefix query", err) + return nil, errors.Wrap("failed to create collection prefix query", err) } defer func() { if err := q.Close(); err != nil { diff --git a/db/collection_delete.go b/db/collection_delete.go index c92c198bc9..844b14cc6e 100644 --- a/db/collection_delete.go +++ b/db/collection_delete.go @@ -30,8 +30,8 @@ import ( ) var ( - ErrDeleteTargetEmpty = errors.New("The doc delete targeter cannot be empty") - ErrDeleteEmpty = errors.New("The doc delete cannot be empty") + ErrDeleteTargetEmpty = errors.New("the doc delete targeter cannot be empty") + ErrDeleteEmpty = errors.New("the doc delete cannot be empty") ) // DeleteWith deletes a target document. Target can be a Filter statement, @@ -293,7 +293,7 @@ func (c *collection) applyFullDelete( // Get all the heads (cids). heads, _, err := headset.List(ctx) if err != nil { - return errors.Wrap("Failed to get document heads", err) + return errors.Wrap("failed to get document heads", err) } dagDel := newDagDeleter(txn.DAGstore()) diff --git a/db/collection_test.go b/db/collection_test.go index 3e284604b5..80641d9b9f 100644 --- a/db/collection_test.go +++ b/db/collection_test.go @@ -101,7 +101,7 @@ func TestNewCollectionReturnsErrorGivenDuplicateSchema(t *testing.T) { assert.NoError(t, err) _, err = newTestCollectionWithSchema(ctx, db) - assert.Errorf(t, err, "Collection already exists") + assert.Errorf(t, err, "collection already exists") } func TestNewCollectionReturnsErrorGivenNoFields(t *testing.T) { @@ -117,7 +117,7 @@ func TestNewCollectionReturnsErrorGivenNoFields(t *testing.T) { } _, err = db.CreateCollection(ctx, desc) - assert.EqualError(t, err, "Collection schema has no fields") + assert.EqualError(t, err, "collection schema has no fields") } func TestNewCollectionReturnsErrorGivenNoName(t *testing.T) { @@ -133,7 +133,7 @@ func TestNewCollectionReturnsErrorGivenNoName(t *testing.T) { } _, err = db.CreateCollection(ctx, desc) - assert.EqualError(t, err, "Collection requires name to not be empty") + assert.EqualError(t, err, "collection requires name to not be empty") } func TestNewCollectionReturnsErrorGivenNoKeyField(t *testing.T) { @@ -155,7 +155,7 @@ func TestNewCollectionReturnsErrorGivenNoKeyField(t *testing.T) { } _, err = db.CreateCollection(ctx, desc) - assert.EqualError(t, err, "Collection schema first field must be a DocKey") + assert.EqualError(t, err, "collection schema first field must be a DocKey") } func TestNewCollectionReturnsErrorGivenKeyFieldIsNotFirstField(t *testing.T) { @@ -181,7 +181,7 @@ func TestNewCollectionReturnsErrorGivenKeyFieldIsNotFirstField(t *testing.T) { } _, err = db.CreateCollection(ctx, desc) - assert.EqualError(t, err, "Collection schema first field must be a DocKey") + assert.EqualError(t, err, "collection schema first field must be a DocKey") } func TestNewCollectionReturnsErrorGivenFieldWithNoName(t *testing.T) { @@ -207,7 +207,7 @@ func TestNewCollectionReturnsErrorGivenFieldWithNoName(t *testing.T) { } _, err = db.CreateCollection(ctx, desc) - assert.EqualError(t, err, "Collection schema field missing Name") + assert.EqualError(t, err, "collection schema field missing Name") } func TestNewCollectionReturnsErrorGivenFieldWithNoKind(t *testing.T) { @@ -232,7 +232,7 @@ func TestNewCollectionReturnsErrorGivenFieldWithNoKind(t *testing.T) { } _, err = db.CreateCollection(ctx, desc) - assert.EqualError(t, err, "Collection schema field missing FieldKind") + assert.EqualError(t, err, "collection schema field missing FieldKind") } func TestNewCollectionReturnsErrorGivenFieldWithNoType(t *testing.T) { @@ -257,7 +257,7 @@ func TestNewCollectionReturnsErrorGivenFieldWithNoType(t *testing.T) { } _, err = db.CreateCollection(ctx, desc) - assert.EqualError(t, err, "Collection schema field missing CRDT type") + assert.EqualError(t, err, "collection schema field missing CRDT type") } func TestGetCollectionByName(t *testing.T) { @@ -303,5 +303,5 @@ func TestGetCollectionByNameReturnsErrorGivenEmptyString(t *testing.T) { assert.NoError(t, err) _, err = db.GetCollectionByName(ctx, "") - assert.EqualError(t, err, "Collection name can't be empty") + assert.EqualError(t, err, "collection name can't be empty") } diff --git a/db/collection_update.go b/db/collection_update.go index 1c89400388..41237e5e1f 100644 --- a/db/collection_update.go +++ b/db/collection_update.go @@ -29,10 +29,10 @@ import ( ) var ( - ErrUpdateTargetEmpty = errors.New("The doc update targeter cannot be empty") - ErrUpdateEmpty = errors.New("The doc update cannot be empty") + ErrUpdateTargetEmpty = errors.New("the doc update targeter cannot be empty") + ErrUpdateEmpty = errors.New("the doc update cannot be empty") ErrInvalidMergeValueType = errors.New( - "The type of value in the merge patch doesn't match the schema", + "the type of value in the merge patch doesn't match the schema", ) ) @@ -604,7 +604,7 @@ func (c *collection) makeSelectionQuery( switch fval := filter.(type) { case string: if fval == "" { - return nil, errors.New("Invalid filter") + return nil, errors.New("invalid filter") } var p *parser.Filter p, err = parser.NewFilterFromString(fval) @@ -615,10 +615,10 @@ func (c *collection) makeSelectionQuery( case *mapper.Filter: f = fval default: - return nil, errors.New("Invalid filter") + return nil, errors.New("invalid filter") } if filter == "" { - return nil, errors.New("Invalid filter") + return nil, errors.New("invalid filter") } slct, err := c.makeSelectLocal(f, mapping) if err != nil { @@ -697,7 +697,7 @@ func (c *collection) getTargetKeyForPatchPath( //nolint:unused ) (string, error) { _, length := splitPatchPath(path) if length == 0 { - return "", errors.New("Invalid patch op path") + return "", errors.New("invalid patch op path") } return "", nil diff --git a/db/db.go b/db/db.go index ba5c50a51d..127617f10b 100644 --- a/db/db.go +++ b/db/db.go @@ -38,9 +38,9 @@ var ( log = logging.MustNewLogger("defra.db") // ErrDocVerification occurs when a documents contents fail the verification during a Create() // call against the supplied Document Key. - ErrDocVerification = errors.New("The document verification failed") + ErrDocVerification = errors.New("the document verification failed") - ErrOptionsEmpty = errors.New("Empty options configuration provided") + ErrOptionsEmpty = errors.New("empty options configuration provided") ) // make sure we match our client interface @@ -198,11 +198,11 @@ func (db *db) GetRelationshipIdField(fieldName, targetType, thisType string) (st rm := db.schema.Relations rel := rm.GetRelationByDescription(fieldName, targetType, thisType) if rel == nil { - return "", errors.New("Relation does not exists") + return "", errors.New("relation does not exists") } subtypefieldname, _, ok := rel.GetFieldFromSchemaType(targetType) if !ok { - return "", errors.New("Relation is missing referenced field") + return "", errors.New("relation is missing referenced field") } return subtypefieldname, nil } diff --git a/db/fetcher/dag.go b/db/fetcher/dag.go index 0fd2f6861a..68369623e4 100644 --- a/db/fetcher/dag.go +++ b/db/fetcher/dag.go @@ -56,7 +56,7 @@ func (hf *HeadFetcher) Start( ) error { numspans := len(spans.Value) if numspans == 0 { - return errors.New("HeadFetcher must have at least one span") + return errors.New("headFetcher must have at least one span") } else if numspans > 1 { // if we have multiple spans, we need to sort them by their start position // so we can do a single iterative sweep @@ -135,7 +135,7 @@ func (hf *HeadFetcher) FetchNext() (*cid.Cid, error) { } if hf.kv == nil { - return nil, errors.New("Failed to get head, fetcher hasn't been initialized or started") + return nil, errors.New("failed to get head, fetcher hasn't been initialized or started") } if hf.fieldId.HasValue() && hf.fieldId.Value() != hf.kv.Key.FieldId { @@ -183,12 +183,12 @@ 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("Failed to get next query result ", err) + return nil, 0, errors.Wrap("failed to get next query result ", err) } headKey := ds.NewKey(strings.TrimPrefix(r.Key, hh.namespace.String())) headCid, err := dshelp.DsKeyToCid(headKey) if err != nil { - return nil, 0, errors.Wrap("Failed to get CID from key ", err) + return nil, 0, errors.Wrap("failed to get CID from key ", err) } height, n := binary.Uvarint(r.Value) if n <= 0 { diff --git a/db/fetcher/fetcher.go b/db/fetcher/fetcher.go index e54feb9ae7..2d6d7b634d 100644 --- a/db/fetcher/fetcher.go +++ b/db/fetcher/fetcher.go @@ -71,7 +71,7 @@ func (df *DocumentFetcher) Init( reverse bool, ) error { if col.Schema.IsEmpty() { - return errors.New("DocumentFetcher must be given a schema") + return errors.New("documentFetcher must be given a schema") } df.col = col @@ -104,11 +104,11 @@ func (df *DocumentFetcher) Init( // Start implements DocumentFetcher func (df *DocumentFetcher) Start(ctx context.Context, txn datastore.Txn, spans core.Spans) error { if df.col == nil { - return errors.New("DocumentFetcher cannot be started without a CollectionDescription") + return errors.New("documentFetcher cannot be started without a CollectionDescription") } if df.doc == nil { return errors.New( - "DocumentFetcher cannot be started without an initialized document object", + "documentFetcher cannot be started without an initialized document object", ) } @@ -262,7 +262,7 @@ func (df *DocumentFetcher) processKV(kv *core.KeyValue) error { // return nil // } if df.doc == nil { - return errors.New("Failed to process KV, uninitialized document object") + return errors.New("failed to process KV, uninitialized document object") } if !df.isReadingDocument { @@ -283,7 +283,7 @@ func (df *DocumentFetcher) processKV(kv *core.KeyValue) error { } fieldDesc, exists := df.schemaFields[fieldID] if !exists { - return errors.New("Found field with no matching FieldDescription") + return errors.New("found field with no matching FieldDescription") } // @todo: Secondary Index might not have encoded FieldIDs @@ -307,7 +307,7 @@ func (df *DocumentFetcher) FetchNext(ctx context.Context) (*encodedDocument, err } if df.kv == nil { - return nil, errors.New("Failed to get document, fetcher hasn't been initalized or started") + return nil, errors.New("failed to get document, fetcher hasn't been initalized or started") } // save the DocKey of the current kv pair so we can track when we cross the doc pair boundries // keyparts := df.kv.Key.List() diff --git a/db/fetcher/versioned.go b/db/fetcher/versioned.go index 5946a6be85..14b9f1e94a 100644 --- a/db/fetcher/versioned.go +++ b/db/fetcher/versioned.go @@ -118,7 +118,7 @@ func (vf *VersionedFetcher) Init( // Start serializes the correct state accoriding to the Key and CID func (vf *VersionedFetcher) Start(ctx context.Context, txn datastore.Txn, spans core.Spans) error { if vf.col == nil { - return errors.New("VersionedFetcher cannot be started without a CollectionDescription") + return errors.New("versionedFetcher cannot be started without a CollectionDescription") } if len(spans.Value) != 1 { @@ -244,7 +244,7 @@ func (vf *VersionedFetcher) seekTo(c cid.Cid) error { } err := vf.merge(cc) if err != nil { - return errors.Wrap("Failed merging state", err) + return errors.Wrap("failed merging state", err) } } @@ -422,7 +422,7 @@ func (vf *VersionedFetcher) getDAGNode(c cid.Cid) (*dag.ProtoNode, error) { // get Block blk, err := vf.store.DAGstore().Get(vf.ctx, c) if err != nil { - return nil, errors.Wrap("Failed to get DAG Node", err) + return nil, errors.Wrap("failed to get DAG Node", err) } // get node diff --git a/go.mod b/go.mod index 76f9bbc706..22d947a41c 100644 --- a/go.mod +++ b/go.mod @@ -26,10 +26,8 @@ require ( github.com/ipfs/go-merkledag v0.8.0 github.com/jbenet/goprocess v0.1.4 github.com/libp2p/go-libp2p v0.23.2 - github.com/libp2p/go-libp2p-core v0.20.0 github.com/libp2p/go-libp2p-gostream v0.3.1 github.com/libp2p/go-libp2p-kad-dht v0.18.0 - github.com/libp2p/go-libp2p-peerstore v0.8.0 github.com/libp2p/go-libp2p-pubsub v0.8.1 github.com/libp2p/go-libp2p-record v0.2.0 github.com/mitchellh/mapstructure v1.5.0 @@ -114,6 +112,7 @@ require ( github.com/libp2p/go-flow-metrics v0.1.0 // indirect github.com/libp2p/go-libp2p-asn-util v0.2.0 // indirect github.com/libp2p/go-libp2p-connmgr v0.4.0 // indirect + github.com/libp2p/go-libp2p-core v0.20.0 // indirect github.com/libp2p/go-libp2p-kbucket v0.4.7 // indirect github.com/libp2p/go-libp2p-routing-helpers v0.2.3 // indirect github.com/libp2p/go-msgio v0.2.0 // indirect diff --git a/go.sum b/go.sum index 9b7b90450b..851a2b23fd 100644 --- a/go.sum +++ b/go.sum @@ -768,7 +768,6 @@ github.com/libp2p/go-libp2p-peerstore v0.2.2/go.mod h1:NQxhNjWxf1d4w6PihR8btWIRj github.com/libp2p/go-libp2p-peerstore v0.2.6/go.mod h1:ss/TWTgHZTMpsU/oKVVPQCGuDHItOpf2W8RxAi50P2s= github.com/libp2p/go-libp2p-peerstore v0.2.7/go.mod h1:ss/TWTgHZTMpsU/oKVVPQCGuDHItOpf2W8RxAi50P2s= github.com/libp2p/go-libp2p-peerstore v0.8.0 h1:bzTG693TA1Ju/zKmUCQzDLSqiJnyRFVwPpuloZ/OZtI= -github.com/libp2p/go-libp2p-peerstore v0.8.0/go.mod h1:9geHWmNA3YDlQBjL/uPEJD6vpDK12aDNlUNHJ6kio/s= github.com/libp2p/go-libp2p-pnet v0.2.0/go.mod h1:Qqvq6JH/oMZGwqs3N1Fqhv8NVhrdYcO0BW4wssv21LA= github.com/libp2p/go-libp2p-protocol v0.0.1/go.mod h1:Af9n4PiruirSDjHycM1QuiMi/1VZNHYcK8cLgFJLZ4s= github.com/libp2p/go-libp2p-protocol v0.1.0/go.mod h1:KQPHpAabB57XQxGrXCNvbL6UEXfQqUgC/1adR2Xtflk= diff --git a/mapper/descriptions.go b/mapper/descriptions.go index 4d98dfbd7c..1d65820f3b 100644 --- a/mapper/descriptions.go +++ b/mapper/descriptions.go @@ -50,7 +50,7 @@ func (r *DescriptionsRepo) getCollectionDesc(name string) (client.CollectionDesc key := core.NewCollectionKey(name) buf, err := r.txn.Systemstore().Get(r.ctx, key.ToDS()) if err != nil { - return client.CollectionDescription{}, errors.Wrap("Failed to get collection description", err) + return client.CollectionDescription{}, errors.Wrap("failed to get collection description", err) } desc := client.CollectionDescription{} diff --git a/mapper/mapper.go b/mapper/mapper.go index 9591dc8895..db11f51844 100644 --- a/mapper/mapper.go +++ b/mapper/mapper.go @@ -289,7 +289,7 @@ func resolveAggregates( if !isHostSelectable { // I believe this is dead code as the gql library should always catch this error first return nil, errors.New( - "Aggregate target host must be selectable, but was not", + "aggregate target host must be selectable, but was not", ) } @@ -748,7 +748,7 @@ func resolveInnerFilterDependencies( host, isSelect := existingField.AsSelect() if !isSelect { // This should never be possible - return nil, errors.New("Host must be a Select, but was not") + return nil, errors.New("host must be a Select, but was not") } return host, nil }) @@ -759,7 +759,7 @@ func resolveInnerFilterDependencies( } if !hasHost { // This should never be possible - return nil, errors.New("Failed to find host field") + return nil, errors.New("failed to find host field") } childFields, err := resolveInnerFilterDependencies( diff --git a/merkle/clock/clock.go b/merkle/clock/clock.go index 44b7ba76b9..31a2edec5e 100644 --- a/merkle/clock/clock.go +++ b/merkle/clock/clock.go @@ -104,7 +104,7 @@ func (mc *MerkleClock) AddDAGNode( // write the delta and heads to a new block nd, err := mc.putBlock(ctx, heads, height, delta) if err != nil { - return nil, errors.Wrap("Error adding block ", err) + return nil, errors.Wrap("could not add block ", err) } // apply the new node and merge the delta with state diff --git a/merkle/clock/heads.go b/merkle/clock/heads.go index cc7763385e..7aec511231 100644 --- a/merkle/clock/heads.go +++ b/merkle/clock/heads.go @@ -160,7 +160,7 @@ func (hh *heads) List(ctx context.Context) ([]cid.Cid, uint64, error) { var maxHeight uint64 for r := range results.Next() { if r.Error != nil { - return nil, 0, errors.Wrap("Failed to get next query result ", r.Error) + return nil, 0, errors.Wrap("failed to get next query result ", r.Error) } headKey, err := core.NewHeadStoreKey(r.Key) diff --git a/merkle/crdt/factory.go b/merkle/crdt/factory.go index 47ea6e3cb1..62ff080a6a 100644 --- a/merkle/crdt/factory.go +++ b/merkle/crdt/factory.go @@ -18,7 +18,7 @@ import ( ) var ( - ErrFactoryTypeNoExist = errors.New("No such factory for the given type exists") + ErrFactoryTypeNoExist = errors.New("no such factory for the given type exists") ) // MerkleCRDTInitFn instantiates a MerkleCRDT with a given key. diff --git a/net/api/client/client.go b/net/api/client/client.go index 62b5600fef..30a0178bbf 100644 --- a/net/api/client/client.go +++ b/net/api/client/client.go @@ -52,7 +52,7 @@ func (c *Client) AddReplicator( paddr ma.Multiaddr, ) (peer.ID, error) { if len(collection) == 0 { - return "", errors.New("Collection can't be empty") + return "", errors.New("collection can't be empty") } if paddr == nil { return "", errors.New("target address can't be empty") @@ -62,7 +62,7 @@ func (c *Client) AddReplicator( Addr: paddr.Bytes(), }) if err != nil { - return "", errors.Wrap("AddReplicator request failed", err) + return "", errors.Wrap("could not add replicator", err) } return peer.IDFromBytes(resp.PeerID) } diff --git a/net/client.go b/net/client.go index 8bbbc87c2a..e82ec09990 100644 --- a/net/client.go +++ b/net/client.go @@ -36,7 +36,7 @@ var ( func (s *server) pushLog(ctx context.Context, evt client.UpdateEvent, pid peer.ID) error { dockey, err := client.NewDocKeyFromString(evt.DocKey) if err != nil { - return errors.Wrap("Failed to get DocKey from broadcast message", err) + return errors.Wrap("failed to get DocKey from broadcast message", err) } log.Debug( ctx, @@ -65,7 +65,7 @@ func (s *server) pushLog(ctx context.Context, evt client.UpdateEvent, pid peer.I client, err := s.dial(pid) // grpc dial over p2p stream if err != nil { - return errors.Wrap("Failed to push log", err) + return errors.Wrap("failed to push log", err) } cctx, cancel := context.WithTimeout(ctx, PushTimeout) diff --git a/net/peer.go b/net/peer.go index b1fff3d361..b2c42d0a1b 100644 --- a/net/peer.go +++ b/net/peer.go @@ -93,7 +93,7 @@ func NewPeer( dialOptions []grpc.DialOption, ) (*Peer, error) { if db == nil { - return nil, errors.New("Database object can't be empty") + return nil, errors.New("database object can't be empty") } ctx, cancel := context.WithCancel(ctx) @@ -281,7 +281,7 @@ func (p *Peer) AddReplicator( // verify collection col, err := p.db.GetCollectionByName(ctx, collectionName) if err != nil { - return pid, errors.Wrap("Failed to get collection for replicator", err) + return pid, errors.Wrap("failed to get collection for replicator", err) } // extra peerID @@ -297,7 +297,7 @@ func (p *Peer) AddReplicator( // make sure it's not ourselves if pid == p.host.ID() { - return pid, errors.New("Can't target ourselves as a replicator") + return pid, errors.New("can't target ourselves as a replicator") } // make sure we're not duplicating things @@ -332,7 +332,7 @@ func (p *Peer) AddReplicator( // create read only txn and assign to col txn, err := p.db.NewTxn(ctx, true) if err != nil { - return pid, errors.Wrap("Failed to get txn", err) + return pid, errors.Wrap("failed to get txn", err) } col = col.WithTxn(txn) @@ -421,7 +421,7 @@ func (p *Peer) AddReplicator( func (p *Peer) handleDocCreateLog(evt client.UpdateEvent) error { dockey, err := client.NewDocKeyFromString(evt.DocKey) if err != nil { - return errors.Wrap("Failed to get DocKey from broadcast message", err) + return errors.Wrap("failed to get DocKey from broadcast message", err) } // push to each peer (replicator) @@ -433,7 +433,7 @@ func (p *Peer) handleDocCreateLog(evt client.UpdateEvent) error { func (p *Peer) handleDocUpdateLog(evt client.UpdateEvent) error { dockey, err := client.NewDocKeyFromString(evt.DocKey) if err != nil { - return errors.Wrap("Failed to get DocKey from broadcast message", err) + return errors.Wrap("failed to get DocKey from broadcast message", err) } log.Debug( p.ctx, diff --git a/net/process.go b/net/process.go index d75b42d153..589b0ce61a 100644 --- a/net/process.go +++ b/net/process.go @@ -54,7 +54,7 @@ func (p *Peer) processLog( // check if we already have this block // exists, err := txn.DAGstore().Has(ctx, c) // if err != nil { - // return nil, errors.Wrap("Failed to check for existing block %s", c, err) + // return nil, errors.Wrap("failed to check for existing block %s", c, err) // } // if exists { // log.Debugf("Already have block %s locally, skipping.", c) @@ -68,7 +68,7 @@ func (p *Peer) processLog( delta, err := crdt.DeltaDecode(nd) if err != nil { - return nil, errors.Wrap("Failed to decode delta object", err) + return nil, errors.Wrap("failed to decode delta object", err) } log.Debug( @@ -130,7 +130,7 @@ func initCRDTForType( func decodeBlockBuffer(buf []byte, cid cid.Cid) (ipld.Node, error) { blk, err := blocks.NewBlockWithCid(buf, cid) if err != nil { - return nil, errors.Wrap("Failed to create block", err) + return nil, errors.Wrap("failed to create block", err) } return format.Decode(blk) } diff --git a/net/server.go b/net/server.go index c576eaac00..ca5450e684 100644 --- a/net/server.go +++ b/net/server.go @@ -74,7 +74,7 @@ func newServer(p *Peer, db client.DB, opts ...grpc.DialOption) (*server, error) log.Debug(p.ctx, "Getting all existing DocKey...") keyResults, err := s.listAllDocKeys() if err != nil { - return nil, errors.Wrap("Failed to get DocKeys for pubsub topic registration", err) + return nil, errors.Wrap("failed to get DocKeys for pubsub topic registration", err) } i := 0 @@ -164,7 +164,7 @@ func (s *server) PushLog(ctx context.Context, req *pb.PushLogRequest) (*pb.PushL // handleComposite nd, err := decodeBlockBuffer(req.Body.Log.Block, cid) if err != nil { - return nil, errors.Wrap("Failed to decode block to ipld.Node", err) + return nil, errors.Wrap("failed to decode block to ipld.Node", err) } cids, err := s.peer.processLog(ctx, col, docKey, cid, "", nd, getter) if err != nil { diff --git a/planner/commit.go b/planner/commit.go index 9dae353744..ce64aace55 100644 --- a/planner/commit.go +++ b/planner/commit.go @@ -299,7 +299,7 @@ func (n *dagScanNode) dagBlockToNodeDoc(block blocks.Block) (core.Doc, []*ipld.L prio, ok := delta["Priority"].(uint64) if !ok { - return core.Doc{}, nil, errors.New("Commit Delta missing priority key") + return core.Doc{}, nil, errors.New("commit Delta missing priority key") } n.parsed.DocumentMapping.SetFirstOfName(&commit, "height", int64(prio)) diff --git a/planner/create.go b/planner/create.go index e628a40741..a4709cdac4 100644 --- a/planner/create.go +++ b/planner/create.go @@ -54,7 +54,7 @@ func (n *createNode) Init() error { return nil } func (n *createNode) Start() error { // parse the doc if n.newDocStr == "" { - return errors.New("Invalid document to create") + return errors.New("invalid document to create") } doc, err := client.NewDocFromJSON([]byte(n.newDocStr)) diff --git a/planner/datasource.go b/planner/datasource.go index 2e338954ab..4b867422fa 100644 --- a/planner/datasource.go +++ b/planner/datasource.go @@ -64,7 +64,7 @@ func (p *Planner) getCollectionDesc(name string) (client.CollectionDescription, var desc client.CollectionDescription buf, err := p.txn.Systemstore().Get(p.ctx, key.ToDS()) if err != nil { - return desc, errors.Wrap("Failed to get collection description", err) + return desc, errors.Wrap("failed to get collection description", err) } err = json.Unmarshal(buf, &desc) diff --git a/planner/executor.go b/planner/executor.go index c1d392258b..e2fc5c0ef0 100644 --- a/planner/executor.go +++ b/planner/executor.go @@ -41,7 +41,7 @@ type QueryExecutor struct { func NewQueryExecutor(manager *schema.SchemaManager) (*QueryExecutor, error) { if manager == nil { - return nil, errors.New("SchemaManager cannot be nil") + return nil, errors.New("schemaManager cannot be nil") } return &QueryExecutor{ @@ -56,7 +56,7 @@ func (e *QueryExecutor) MakeSelectQuery( selectStmt *mapper.Select, ) (Query, error) { if selectStmt == nil { - return nil, errors.New("Cannot create query without a selection") + return nil, errors.New("cannot create query without a selection") } planner := makePlanner(ctx, db, txn) return planner.makePlan(selectStmt) diff --git a/planner/multi.go b/planner/multi.go index fd69077833..2400c39256 100644 --- a/planner/multi.go +++ b/planner/multi.go @@ -392,14 +392,14 @@ func (s *selectNode) addSubPlan(fieldIndex int, plan planNode) error { m.addChild(fieldIndex, plan) s.source = m default: - return errors.New("Sub plan needs to be either a MergeNode or an AppendNode") + return errors.New("sub plan needs to be either a MergeNode or an AppendNode") } // source is a mergeNode, like a TypeJoin case mergeNode: origScan, _ := walkAndFindPlanType[*scanNode](plan) if origScan == nil { - return errors.New("Failed to find original scan node in plan graph") + return errors.New("failed to find original scan node in plan graph") } // create our new multiscanner multiscan := &multiScanNode{scanNode: origScan} @@ -435,7 +435,7 @@ func (s *selectNode) addSubPlan(fieldIndex int, plan planNode) error { case mergeNode: multiscan, sourceIsMultiscan := node.Source().(*multiScanNode) if !sourceIsMultiscan { - return errors.New("Merge node source must be a multiScanNode") + return errors.New("merge node source must be a multiScanNode") } // replace our new node internal scanNode with our existing multiscanner @@ -446,7 +446,7 @@ func (s *selectNode) addSubPlan(fieldIndex int, plan planNode) error { // add our newly updated plan to the multinode node.addChild(fieldIndex, plan) default: - return errors.New("Sub plan needs to be either a MergeNode or an AppendNode") + return errors.New("sub plan needs to be either a MergeNode or an AppendNode") } } return nil diff --git a/planner/planner.go b/planner/planner.go index 6d280c4061..07e3c69807 100644 --- a/planner/planner.go +++ b/planner/planner.go @@ -110,12 +110,12 @@ func (p *Planner) newPlan(stmt any) (planNode, error) { } else if len(n.Mutations) > 0 { return p.newPlan(n.Mutations[0]) // @todo: handle multiple mutation statements } else { - return nil, errors.New("Query is missing query or mutation statements") + return nil, errors.New("query is missing query or mutation statements") } case *parser.OperationDefinition: if len(n.Selections) == 0 { - return nil, errors.New("OperationDefinition is missing selections") + return nil, errors.New("operationDefinition is missing selections") } return p.newPlan(n.Selections[0]) @@ -313,7 +313,7 @@ func (p *Planner) expandTypeIndexJoinPlan(plan *typeIndexJoin, parentPlan *selec case *typeJoinMany: return p.expandPlan(node.subType, parentPlan) } - return errors.New("Unknown type index join plan") + return errors.New("unknown type index join plan") } func (p *Planner) expandGroupNodePlan(plan *selectTopNode) error { @@ -325,7 +325,7 @@ func (p *Planner) expandGroupNodePlan(plan *selectTopNode) error { if !hasScanNode { commitNode, hasCommitNode := walkAndFindPlanType[*dagScanNode](plan.plan) if !hasCommitNode { - return errors.New("Failed to identify group source") + return errors.New("failed to identify group source") } sourceNode = commitNode } diff --git a/planner/select.go b/planner/select.go index b389bf2b74..b096d63191 100644 --- a/planner/select.go +++ b/planner/select.go @@ -224,7 +224,7 @@ func (n *selectNode) initSource() ([]aggregateNode, error) { c, err := cid.Decode(n.parsed.Cid.Value()) if err != nil { return nil, errors.Wrap( - "Failed to propagate VersionFetcher span, invalid CID", + "failed to propagate VersionFetcher span, invalid CID", err, ) } diff --git a/planner/sum.go b/planner/sum.go index 6cfbd21f7a..f8a9024fb1 100644 --- a/planner/sum.go +++ b/planner/sum.go @@ -96,7 +96,7 @@ func (p *Planner) isValueFloat( child, isChildSelect := parent.FieldAt(source.Index).AsSelect() if !isChildSelect { - return false, errors.New("Expected child select but none was found") + return false, errors.New("expected child select but none was found") } if _, isAggregate := parserTypes.Aggregates[source.ChildTarget.Name]; isAggregate { diff --git a/planner/top.go b/planner/top.go index ad512edd4f..21e8a84b9c 100644 --- a/planner/top.go +++ b/planner/top.go @@ -164,7 +164,7 @@ func (n *topLevelNode) Next() (bool, error) { return false, err } if !hasChild { - return false, errors.New("Expected child value, however none was yielded") + return false, errors.New("expected child value, however none was yielded") } n.currentValue = child.Value() diff --git a/planner/type_join.go b/planner/type_join.go index 511ad8525e..237883fd79 100644 --- a/planner/type_join.go +++ b/planner/type_join.go @@ -94,7 +94,7 @@ func (p *Planner) makeTypeIndexJoin( } else if schema.IsOneToMany(meta) { // Many side of One-to-Many joinPlan, err = p.makeTypeJoinMany(parent, source, subType) } else { // more to come, Many-to-Many, Embedded? - return nil, errors.New("Failed sub selection, unknown relation type") + return nil, errors.New("failed sub selection, unknown relation type") } if err != nil { return nil, err diff --git a/planner/versionedscan.go b/planner/versionedscan.go index 041cd6b919..d0e122f702 100644 --- a/planner/versionedscan.go +++ b/planner/versionedscan.go @@ -66,7 +66,7 @@ func (n *versionedScanNode) Start() error { func (n *versionedScanNode) initScan() error { if n.key.DocKey == "" || n.version.Equals(emptyCID) { - return errors.New("VersionedScan is missing either a DocKey or VersionCID") + return errors.New("versionedScan is missing either a DocKey or VersionCID") } // create a span of the form {DocKey, VersionCID} diff --git a/query/graphql/parser/filter.go b/query/graphql/parser/filter.go index be1bbf39c8..7cd7c156fc 100644 --- a/query/graphql/parser/filter.go +++ b/query/graphql/parser/filter.go @@ -81,7 +81,7 @@ func ParseConditionsInOrder(stmt *ast.ObjectValue) ([]parserTypes.OrderCondition if v, ok := cond.([]parserTypes.OrderCondition); ok { return v, nil } - return nil, errors.New("Failed to parse statement") + return nil, errors.New("failed to parse statement") } func parseConditionsInOrder(stmt *ast.ObjectValue) (any, error) { @@ -100,7 +100,7 @@ func parseConditionsInOrder(stmt *ast.ObjectValue) (any, error) { case string: // base direction parsed (hopefully, check NameToOrderDirection) dir, ok := parserTypes.NameToOrderDirection[v] if !ok { - return nil, errors.New("Invalid order direction string") + return nil, errors.New("invalid order direction string") } conditions = append(conditions, parserTypes.OrderCondition{ Field: name, @@ -119,7 +119,7 @@ func parseConditionsInOrder(stmt *ast.ObjectValue) (any, error) { } default: - return nil, errors.New("Unexpected parsed type for parseConditionInOrder") + return nil, errors.New("unexpected parsed type for parseConditionInOrder") } } @@ -137,7 +137,7 @@ func ParseConditions(stmt *ast.ObjectValue) (map[string]any, error) { if v, ok := cond.(map[string]any); ok { return v, nil } - return nil, errors.New("Failed to parse statement") + return nil, errors.New("failed to parse statement") } func parseConditions(stmt *ast.ObjectValue) (any, error) { @@ -194,7 +194,7 @@ func parseVal(val ast.Value, recurseFn parseFn) (any, error) { return conditions, nil } - return nil, errors.New("Failed to parse condition value from query filter statement") + return nil, errors.New("failed to parse condition value from query filter statement") } /* diff --git a/query/graphql/parser/query.go b/query/graphql/parser/query.go index b157521efc..3bfc760be7 100644 --- a/query/graphql/parser/query.go +++ b/query/graphql/parser/query.go @@ -160,7 +160,7 @@ func (c Field) GetRoot() parserTypes.SelectionType { // Requires a non-nil doc, will error if given a nil doc. func ParseQuery(doc *ast.Document) (*Query, []error) { if doc == nil { - return nil, []error{errors.New("ParseQuery requires a non-nil ast.Document")} + return nil, []error{errors.New("parseQuery requires a non-nil ast.Document")} } q := &Query{ Statement: doc, @@ -186,7 +186,7 @@ func ParseQuery(doc *ast.Document) (*Query, []error) { } q.Mutations = append(q.Mutations, mdef) } else { - return nil, []error{errors.New("Unknown GraphQL operation type")} + return nil, []error{errors.New("unknown GraphQL operation type")} } } } @@ -427,6 +427,6 @@ func parseAPIQuery(field *ast.Field) (Selection, error) { case "latestCommits", "commits": return parseCommitSelect(field) default: - return nil, errors.New("Unknown query") + return nil, errors.New("unknown query") } } diff --git a/query/graphql/schema/descriptions.go b/query/graphql/schema/descriptions.go index 3a1a9a80e7..a92a7e440c 100644 --- a/query/graphql/schema/descriptions.go +++ b/query/graphql/schema/descriptions.go @@ -197,7 +197,7 @@ func (g *Generator) CreateDescriptions( _, fieldRelationType, ok := rel.GetField(schemaName, fname) if !ok { - return nil, errors.New("Relation is missing field") + return nil, errors.New("relation is missing field") } fd.RelationType = rel.Kind() | fieldRelationType diff --git a/query/graphql/schema/generate.go b/query/graphql/schema/generate.go index 3821ea1add..25bb2e485b 100644 --- a/query/graphql/schema/generate.go +++ b/query/graphql/schema/generate.go @@ -1013,7 +1013,7 @@ func (g *Generator) GenerateMutationInputForGQLType(obj *gql.Object) ([]*gql.Fie typeName := obj.Name() filter, ok := g.manager.schema.TypeMap()[typeName+"FilterArg"].(*gql.InputObject) if !ok { - return nil, errors.New("Missing filter arg for mutation type generation " + typeName) + return nil, errors.New("missing filter arg for mutation type generation " + typeName) } return g.genTypeMutationFields(obj, filter) @@ -1192,14 +1192,14 @@ func (g *Generator) genLeafFilterArgInput(obj gql.Type) *gql.InputObject { operatorType, hasOperatorType := g.manager.schema.TypeMap()[operatorBlockName] if !hasOperatorType { // This should be impossible - return nil, errors.New("Operator block not found", errors.NewKV("Name", operatorBlockName)) + return nil, errors.New("operator block not found", errors.NewKV("Name", operatorBlockName)) } operatorObject, isInputObj := operatorType.(*gql.InputObject) if !isInputObj { // This should be impossible return nil, errors.New( - "Invalid cast", + "invalid cast", errors.NewKV("Expected type", "*gql.InputObject"), errors.NewKV("Actual type", fmt.Sprintf("%T", operatorType)), ) diff --git a/query/graphql/schema/relations.go b/query/graphql/schema/relations.go index 8727f6218f..d542f99880 100644 --- a/query/graphql/schema/relations.go +++ b/query/graphql/schema/relations.go @@ -47,7 +47,7 @@ func (rm *RelationManager) GetRelations() {} func (rm *RelationManager) GetRelation(name string) (*Relation, error) { rel, ok := rm.relations[name] if !ok { - return nil, errors.New("No relation found") + return nil, errors.New("no relation found") } return rel, nil } @@ -105,12 +105,12 @@ func (rm *RelationManager) RegisterSingle( relType client.RelationType, ) (bool, error) { if name == "" { - return false, errors.New("Relation name must be non empty") + return false, errors.New("relation name must be non empty") } // make sure the relation type is ONLY One or Many, not both if relType.IsSet(client.Relation_Type_ONE) == relType.IsSet(client.Relation_Type_MANY) { - return false, errors.New("Relation type can only be either One or Many, not both") + return false, errors.New("relation type can only be either One or Many, not both") } // make a copy of rel type, one goes to the relation.relType, and the other goes into the []types. @@ -200,14 +200,14 @@ type Relation struct { func (r *Relation) finalize() error { // make sure all the types/fields are set if len(r.types) != 2 || len(r.schemaTypes) != 2 || len(r.fields) != 2 { - return errors.New("Relation is missing its defined types and fields") + return errors.New("relation is missing its defined types and fields") } // make sure its one of One-to-One, One-to-Many, Many-to-Many if !r.relType.IsSet(client.Relation_Type_ONEONE) && !r.relType.IsSet(client.Relation_Type_ONEMANY) && !r.relType.IsSet(client.Relation_Type_MANYMANY) { - return errors.New("Relation has an invalid type to be finalize") + return errors.New("relation has an invalid type to be finalize") } // make sure we have a primary set if its a one-to-one or many-to-many diff --git a/tests/bench/bench_util.go b/tests/bench/bench_util.go index 5b3cf076ca..d4472f2386 100644 --- a/tests/bench/bench_util.go +++ b/tests/bench/bench_util.go @@ -79,7 +79,7 @@ func SetupCollections( // b.Logf("Loading schema: \n%s", schema) if err := db.AddSchema(ctx, schema); err != nil { - return nil, errors.Wrap("Couldn't load schema", err) + return nil, errors.Wrap("couldn't load schema", err) } // loop to get collections @@ -170,7 +170,7 @@ func BackfillBenchmarkDB( go func(index int) { docs, err := fixture.GenerateDocs() if err != nil { - errCh <- errors.Wrap("Failed to generate document payload from fixtures", err) + errCh <- errors.Wrap("failed to generate document payload from fixtures", err) return } @@ -179,7 +179,7 @@ func BackfillBenchmarkDB( for j := 0; j < numTypes; j++ { doc, err := client.NewDocFromJSON([]byte(docs[j])) if err != nil { - errCh <- errors.Wrap("Failed to create document from fixture", err) + errCh <- errors.Wrap("failed to create document from fixture", err) return } @@ -197,7 +197,7 @@ func BackfillBenchmarkDB( ) continue } else if err != nil { - errCh <- errors.Wrap("Failed to create document", err) + errCh <- errors.Wrap("failed to create document", err) } keys[j] = doc.Key() break @@ -258,7 +258,7 @@ func newBenchStoreInfo(ctx context.Context, t testing.TB) (dbInfo, error) { } if err != nil { - return nil, errors.Wrap("Failed to create storage backend", err) + return nil, errors.Wrap("failed to create storage backend", err) } return dbi, err } diff --git a/tests/bench/query/planner/utils.go b/tests/bench/query/planner/utils.go index 2d5440f9f3..e1fd28e595 100644 --- a/tests/bench/query/planner/utils.go +++ b/tests/bench/query/planner/utils.go @@ -36,7 +36,7 @@ func runQueryParserBench( for i := 0; i < b.N; i++ { _, err := exec.ParseRequestString(query) if err != nil { - return errors.Wrap("Failed to parse query string", err) + return errors.Wrap("failed to parse query string", err) } } b.StopTimer() @@ -63,18 +63,18 @@ func runMakePlanBench( q, err := exec.ParseRequestString(query) if err != nil { - return errors.Wrap("Failed to parse query string", err) + return errors.Wrap("failed to parse query string", err) } txn, err := db.NewTxn(ctx, false) if err != nil { - return errors.Wrap("Failed to create txn", err) + return errors.Wrap("failed to create txn", err) } b.ResetTimer() for i := 0; i < b.N; i++ { _, err := exec.MakePlanFromParser(ctx, db, txn, q) if err != nil { - return errors.Wrap("Failed to make plan", err) + return errors.Wrap("failed to make plan", err) } } b.StopTimer() diff --git a/tests/integration/collection/update/simple/with_filter_test.go b/tests/integration/collection/update/simple/with_filter_test.go index 9d51588469..db9fdb8457 100644 --- a/tests/integration/collection/update/simple/with_filter_test.go +++ b/tests/integration/collection/update/simple/with_filter_test.go @@ -65,7 +65,7 @@ func TestUpdateWithFilter(t *testing.T) { }, }, }, - ExpectedError: "The updater of a document is of invalid type", + ExpectedError: "the updater of a document is of invalid type", }, { Description: "Test update users with filter and patch updator (not implemented so no change)", Docs: map[string][]string{ diff --git a/tests/integration/collection/update/simple/with_key_test.go b/tests/integration/collection/update/simple/with_key_test.go index 12a24df0f8..8064b42e1c 100644 --- a/tests/integration/collection/update/simple/with_key_test.go +++ b/tests/integration/collection/update/simple/with_key_test.go @@ -63,7 +63,7 @@ func TestUpdateWithKey(t *testing.T) { }, }, }, - ExpectedError: "The updater of a document is of invalid type", + ExpectedError: "the updater of a document is of invalid type", }, { Description: "Test update users with key and patch updator (not implemented so no change)", Docs: map[string][]string{ diff --git a/tests/integration/collection/update/simple/with_keys_test.go b/tests/integration/collection/update/simple/with_keys_test.go index 8aece14158..d556893b6b 100644 --- a/tests/integration/collection/update/simple/with_keys_test.go +++ b/tests/integration/collection/update/simple/with_keys_test.go @@ -79,7 +79,7 @@ func TestUpdateWithKeys(t *testing.T) { }, }, }, - ExpectedError: "The updater of a document is of invalid type", + ExpectedError: "the updater of a document is of invalid type", }, { Description: "Test update users with keys and patch updator (not implemented so no change)", Docs: map[string][]string{ diff --git a/tests/integration/mutation/simple/create/simple_test.go b/tests/integration/mutation/simple/create/simple_test.go index cfe8edee9b..81248cc137 100644 --- a/tests/integration/mutation/simple/create/simple_test.go +++ b/tests/integration/mutation/simple/create/simple_test.go @@ -57,7 +57,7 @@ func TestMutationCreateSimpleDoesNotCreateDocGivenDuplicate(t *testing.T) { }`, }, }, - ExpectedError: "A document with the given dockey already exists", + ExpectedError: "a document with the given dockey already exists", } simpleTests.ExecuteTestCase(t, test) diff --git a/tests/integration/query/simple/with_cid_test.go b/tests/integration/query/simple/with_cid_test.go index bd409c3a08..c776c11a0b 100644 --- a/tests/integration/query/simple/with_cid_test.go +++ b/tests/integration/query/simple/with_cid_test.go @@ -32,7 +32,7 @@ func TestQuerySimpleWithInvalidCid(t *testing.T) { }`, }, }, - ExpectedError: "Failed to propagate VersionFetcher span, invalid CID: selected encoding not supported", + ExpectedError: "failed to propagate VersionFetcher span, invalid CID: selected encoding not supported", } executeTestCase(t, test) diff --git a/tools/configs/golangci.yaml b/tools/configs/golangci.yaml index 020b0ea913..0644ae4333 100644 --- a/tools/configs/golangci.yaml +++ b/tools/configs/golangci.yaml @@ -333,6 +333,33 @@ linters-settings: severity: error - name: error-strings severity: error + - name: string-format + severity: error + arguments: + - - 'errors.New' + - '/^([^A-Z]|$)/' + - must not start with a capital letter + - - 'errors.New' + - '/(^|[^\.!?])$/' + - must not end in punctuation + - - 'fmt.Errorf' + - '/^([^A-Z]|$)/' + - must not start with a capital letter + - - 'fmt.Errorf' + - '/(^|[^\.!?])$/' + - must not end in punctuation + - - 'errors.Wrap' + - '/^([^A-Z]|$)/' + - must not start with a capital letter + - - 'errors.Wrap' + - '/(^|[^\.!?])$/' + - must not end in punctuation + - - 'errors.WithStack' + - '/^([^A-Z]|$)/' + - must not start with a capital letter + - - 'errors.WithStack' + - '/(^|[^\.!?])$/' + - must not end in punctuation staticcheck: # Select the Go version to target.