diff --git a/.golangci.sourceinc.yaml b/.golangci.sourceinc.yaml index db0be534dc..8620778af9 100644 --- a/.golangci.sourceinc.yaml +++ b/.golangci.sourceinc.yaml @@ -133,9 +133,9 @@ linters-settings: # list of functions to exclude from checking, where each entry is a single function to exclude. # see https://github.com/kisielk/errcheck#excluding-functions for details exclude-functions: - - io/ioutil.ReadFile - - io.Copy(*bytes.Buffer) - - io.Copy(os.Stdout) + # - io/ioutil.ReadFile + # - io.Copy(*bytes.Buffer) + # - io.Copy(os.Stdout) errorlint: # Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats @@ -789,7 +789,7 @@ linters: - typecheck - unused - varcheck - # - errcheck + - errcheck # - wrapcheck # - errorlint # - gci diff --git a/api/http/api.go b/api/http/api.go index 7b1dcd26a7..af95135e05 100644 --- a/api/http/api.go +++ b/api/http/api.go @@ -13,6 +13,7 @@ import ( "context" "encoding/json" "io/ioutil" + "log" "net/http" "github.com/multiformats/go-multihash" @@ -39,7 +40,10 @@ func NewServer(db client.DB) *Server { r := chi.NewRouter() r.Use(middleware.Logger) r.Get("/", func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("Welcome to the DefraDB HTTP API. Use /graphql to send queries to the database")) + _, err := w.Write([]byte("Welcome to the DefraDB HTTP API. Use /graphql to send queries to the database")) + if err != nil { + log.Printf("DefraDB HTTP API Welcome message writing failed: %v", err) + } }) r.Get("/ping", s.ping) @@ -52,35 +56,61 @@ func NewServer(db client.DB) *Server { } func (s *Server) Listen(addr string) { - http.ListenAndServe(addr, s.router) + if err := http.ListenAndServe(addr, s.router); err != nil { + log.Fatalln("Error: HTTP Listening and Serving Failed: ", err) + } } func (s *Server) ping(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("pong")) + _, err := w.Write([]byte("pong")) + if err != nil { + log.Printf("Writing pong with HTTP failed: %v", err) + } } func (s *Server) dump(w http.ResponseWriter, r *http.Request) { ctx := context.Background() s.db.PrintDump(ctx) - w.Write([]byte("ok")) + + _, err := w.Write([]byte("ok")) + if err != nil { + log.Printf("Writing ok with HTTP failed: %v", err) + } } func (s *Server) execGQL(w http.ResponseWriter, r *http.Request) { ctx := context.Background() query := r.URL.Query().Get("query") result := s.db.ExecQuery(ctx, query) - json.NewEncoder(w).Encode(result) + + err := json.NewEncoder(w).Encode(result) + if err != nil { + http.Error(w, err.Error(), 500) + return + } } func (s *Server) loadSchema(w http.ResponseWriter, r *http.Request) { ctx := context.Background() var result client.QueryResult sdl, err := ioutil.ReadAll(r.Body) - defer r.Body.Close() + + defer func() { + err = r.Body.Close() + if err != nil { + log.Print(err) // Should this be `log.Fatal(err)` ?? + } + }() if err != nil { result.Errors = []interface{}{err.Error()} - json.NewEncoder(w).Encode(result) + + err = json.NewEncoder(w).Encode(result) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + w.WriteHeader(http.StatusBadRequest) return } @@ -88,7 +118,13 @@ func (s *Server) loadSchema(w http.ResponseWriter, r *http.Request) { err = s.db.AddSchema(ctx, string(sdl)) if err != nil { result.Errors = []interface{}{err.Error()} - json.NewEncoder(w).Encode(result) + + err = json.NewEncoder(w).Encode(result) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + w.WriteHeader(http.StatusBadRequest) return } @@ -96,7 +132,12 @@ func (s *Server) loadSchema(w http.ResponseWriter, r *http.Request) { result.Data = map[string]string{ "result": "success", } - json.NewEncoder(w).Encode(result) + + err = json.NewEncoder(w).Encode(result) + if err != nil { + http.Error(w, err.Error(), 500) + return + } } func (s *Server) getBlock(w http.ResponseWriter, r *http.Request) { @@ -115,7 +156,13 @@ func (s *Server) getBlock(w http.ResponseWriter, r *http.Request) { if err != nil { result.Errors = []interface{}{err.Error()} result.Data = err.Error() - json.NewEncoder(w).Encode(result) + + err = json.NewEncoder(w).Encode(result) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + w.WriteHeader(http.StatusBadRequest) return } @@ -125,7 +172,13 @@ func (s *Server) getBlock(w http.ResponseWriter, r *http.Request) { block, err := s.db.GetBlock(ctx, c) if err != nil { result.Errors = []interface{}{err.Error()} - json.NewEncoder(w).Encode(result) + + err = json.NewEncoder(w).Encode(result) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + w.WriteHeader(http.StatusBadRequest) return } @@ -134,14 +187,26 @@ func (s *Server) getBlock(w http.ResponseWriter, r *http.Request) { if err != nil { result.Errors = []interface{}{err.Error()} result.Data = err.Error() - json.NewEncoder(w).Encode(result) + + err = json.NewEncoder(w).Encode(result) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + w.WriteHeader(http.StatusBadRequest) return } buf, err := nd.MarshalJSON() if err != nil { result.Errors = []interface{}{err.Error()} - json.NewEncoder(w).Encode(result) + + err = json.NewEncoder(w).Encode(result) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + w.WriteHeader(http.StatusBadRequest) return } @@ -151,7 +216,13 @@ func (s *Server) getBlock(w http.ResponseWriter, r *http.Request) { delta, err := reg.DeltaDecode(nd) if err != nil { result.Errors = []interface{}{err.Error()} - json.NewEncoder(w).Encode(result) + + err = json.NewEncoder(w).Encode(result) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + w.WriteHeader(http.StatusBadRequest) return } @@ -159,7 +230,13 @@ func (s *Server) getBlock(w http.ResponseWriter, r *http.Request) { data, err := delta.Marshal() if err != nil { result.Errors = []interface{}{err.Error()} - json.NewEncoder(w).Encode(result) + + err = json.NewEncoder(w).Encode(result) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + w.WriteHeader(http.StatusBadRequest) return } @@ -167,10 +244,14 @@ func (s *Server) getBlock(w http.ResponseWriter, r *http.Request) { // var val interface{} // err = cbor.Unmarshal(delta.Value().([]byte), &val) // if err != nil { - // result.Errors = []interface{}{err.Error()} - // json.NewEncoder(w).Encode(result) - // w.WriteHeader(http.StatusBadRequest) - // return + // result.Errors = []interface{}{err.Error()} + // err = json.NewEncoder(w).Encode(result) + // if err != nil { + // http.Error(w, err.Error(), 500) + // return + // } + // w.WriteHeader(http.StatusBadRequest) + // return // } result.Data = map[string]interface{}{ "block": string(buf), @@ -184,7 +265,13 @@ func (s *Server) getBlock(w http.ResponseWriter, r *http.Request) { if err != nil { result.Errors = []interface{}{err.Error()} result.Data = nil - json.NewEncoder(w).Encode(result) + + err := json.NewEncoder(w).Encode(result) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + w.WriteHeader(http.StatusBadRequest) return } diff --git a/cli/defradb/cmd/blocks_get.go b/cli/defradb/cmd/blocks_get.go index adc31bec70..98d5eb6233 100644 --- a/cli/defradb/cmd/blocks_get.go +++ b/cli/defradb/cmd/blocks_get.go @@ -42,7 +42,15 @@ var getCmd = &cobra.Command{ log.Error("request failed: ", err) return } - defer res.Body.Close() + + defer func() { + err = res.Body.Close() + if err != nil { + // Should this be `log.Fatal` ?? + log.Error("response body closing failed: ", err) + } + }() + buf, err := ioutil.ReadAll(res.Body) if err != nil { log.Error("request failed: ", err) diff --git a/cli/defradb/cmd/dump.go b/cli/defradb/cmd/dump.go index 876854a1e4..a00be3dd17 100644 --- a/cli/defradb/cmd/dump.go +++ b/cli/defradb/cmd/dump.go @@ -37,7 +37,15 @@ var dumpCmd = &cobra.Command{ log.Error("request failed: ", err) return } - defer res.Body.Close() + + defer func() { + err = res.Body.Close() + if err != nil { + // Should this be `log.Fatal` ?? + log.Error("response body closing failed: ", err) + } + }() + buf, err := ioutil.ReadAll(res.Body) if err != nil { log.Error("request failed: ", err) diff --git a/cli/defradb/cmd/ping.go b/cli/defradb/cmd/ping.go index 986f94a319..c71d220591 100644 --- a/cli/defradb/cmd/ping.go +++ b/cli/defradb/cmd/ping.go @@ -1,12 +1,12 @@ -// Copyright 2020 Source Inc. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. +// Copyright 2020 Source Inc. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. package cmd import ( @@ -38,7 +38,15 @@ var pingCmd = &cobra.Command{ log.Error("request failed: ", err) return } - defer res.Body.Close() + + defer func() { + err = res.Body.Close() + if err != nil { + // Should this be `log.Fatal` ?? + log.Error("response body closing failed: ", err) + } + }() + buf, err := ioutil.ReadAll(res.Body) if err != nil { log.Error("request failed: ", err) diff --git a/cli/defradb/cmd/query.go b/cli/defradb/cmd/query.go index a18b474a97..0cfd9f71dd 100644 --- a/cli/defradb/cmd/query.go +++ b/cli/defradb/cmd/query.go @@ -69,7 +69,15 @@ the additional documentation found at: https://hackmd.io/@source/BksQY6Qfw. log.Error("request failed: ", err) return } - defer res.Body.Close() + + defer func() { + err = res.Body.Close() + if err != nil { + // Should this be `log.Fatal` ?? + log.Error("response body closing failed: ", err) + } + }() + buf, err := ioutil.ReadAll(res.Body) if err != nil { log.Error("request failed: ", err) diff --git a/cli/defradb/cmd/root.go b/cli/defradb/cmd/root.go index 610c43e407..730d0cac1b 100644 --- a/cli/defradb/cmd/root.go +++ b/cli/defradb/cmd/root.go @@ -117,12 +117,19 @@ func initConfig() { bs, err := yaml.Marshal(defaultConfig) cobra.CheckErr(err) - viper.ReadConfig(bytes.NewBuffer(bs)) + err = viper.ReadConfig(bytes.NewBuffer(bs)) + cobra.CheckErr(err) + err = viper.WriteConfigAs(home + "/.defradb/" + "config.yaml") cobra.CheckErr(err) } - viper.BindPFlag("database.address", rootCmd.Flags().Lookup("url")) - viper.BindPFlag("database.store", startCmd.Flags().Lookup("store")) - viper.Unmarshal(&config) + err := viper.BindPFlag("database.address", rootCmd.Flags().Lookup("url")) + cobra.CheckErr(err) + + err = viper.BindPFlag("database.store", startCmd.Flags().Lookup("store")) + cobra.CheckErr(err) + + err = viper.Unmarshal(&config) + cobra.CheckErr(err) } diff --git a/cli/defradb/cmd/schema_add.go b/cli/defradb/cmd/schema_add.go index 9beab0546b..dad90065b2 100644 --- a/cli/defradb/cmd/schema_add.go +++ b/cli/defradb/cmd/schema_add.go @@ -54,10 +54,18 @@ var addCmd = &cobra.Command{ endpoint, err := url.Parse(endpointStr) cobra.CheckErr(err) - r, err := http.Post(endpoint.String(), "text", bytes.NewBuffer(schema)) + res, err := http.Post(endpoint.String(), "text", bytes.NewBuffer(schema)) cobra.CheckErr(err) - defer r.Body.Close() - result, err := ioutil.ReadAll(r.Body) + + defer func() { + err = res.Body.Close() + if err != nil { + // Should this be `log.Fatal` ?? + log.Error("response body closing failed: ", err) + } + }() + + result, err := ioutil.ReadAll(res.Body) cobra.CheckErr(err) fmt.Println(string(result)) }, diff --git a/datastores/badger/v3/datastore.go b/datastores/badger/v3/datastore.go index 301f3858d6..7f654cbf01 100644 --- a/datastores/badger/v3/datastore.go +++ b/datastores/badger/v3/datastore.go @@ -849,6 +849,7 @@ func (t *txn) query(q dsq.Query) (dsq.Results, error) { } }) + // nolint:errcheck go qrb.Process.CloseAfterChildren() return qrb.Results(), nil diff --git a/db/collection.go b/db/collection.go index 2574a63a84..04aa907de3 100644 --- a/db/collection.go +++ b/db/collection.go @@ -412,7 +412,10 @@ func (c *Collection) save(ctx context.Context, txn *Txn, doc *document.Document) return err } if val.IsDelete() { - doc.SetAs(v.Name(), nil, v.Type()) + err := doc.SetAs(v.Name(), nil, v.Type()) + if err != nil { + log.Error("Couldn't set document as type: ", v.Type()) + } merge[k] = nil } else { merge[k] = val.Value() diff --git a/db/container/container.go b/db/container/container.go index ff8f7fad28..7b1f3abba0 100644 --- a/db/container/container.go +++ b/db/container/container.go @@ -69,10 +69,9 @@ func (c *DocumentContainer) Swap(i, j int) { c.docs[j] = tmp } -func (c *DocumentContainer) Close() error { +func (c *DocumentContainer) Close() { c.docs = nil c.numDocs = 0 - return nil } func copyMap(m map[string]interface{}) map[string]interface{} { diff --git a/db/db.go b/db/db.go index dbc9510c38..416a78c916 100644 --- a/db/db.go +++ b/db/db.go @@ -190,7 +190,10 @@ func (db *DB) PrintDump(ctx context.Context) { // of resources (IE: Badger instance) func (db *DB) Close() { log.Info("Closing DefraDB process...") - db.rootstore.Close() + err := db.rootstore.Close() + if err != nil { + log.Error("Failure closing running process") + } log.Info("Succesfully closed running process") } @@ -207,7 +210,12 @@ func printStore(ctx context.Context, store core.DSReaderWriter) { panic(err) } - defer results.Close() + defer func() { + err := results.Close() + if err != nil { + log.Error("Failure closing set of query store results") + } + }() for r := range results.Next() { fmt.Println(r.Key, ": ", r.Value) diff --git a/db/sequence.go b/db/sequence.go index b8f88bddb6..116878c5eb 100644 --- a/db/sequence.go +++ b/db/sequence.go @@ -37,7 +37,10 @@ func (db *DB) getSequence(ctx context.Context, key string) (*sequence, error) { _, err := seq.get(ctx) if err == ds.ErrNotFound { - seq.update(ctx) + err = seq.update(ctx) + if err != nil { + return nil, err + } } else if err != nil { return nil, err } diff --git a/document/document.go b/document/document.go index 49a023fccd..7c313620d2 100644 --- a/document/document.go +++ b/document/document.go @@ -309,14 +309,24 @@ func (doc *Document) setAndParseType(field string, value interface{}) error { // Check if its actually a float or just an int if float64(int64(val)) == val { //int - doc.setCBOR(core.LWW_REGISTER, field, int64(val)) + err := doc.setCBOR(core.LWW_REGISTER, field, int64(val)) + if err != nil { + return err + } + } else { //float - doc.setCBOR(core.LWW_REGISTER, field, val) + err := doc.setCBOR(core.LWW_REGISTER, field, val) + if err != nil { + return err + } } // string, bool, and more case string, bool, []interface{}: - doc.setCBOR(core.LWW_REGISTER, field, val) + err := doc.setCBOR(core.LWW_REGISTER, field, val) + if err != nil { + return err + } // sub object, recurse down. // @TODO: Object Definitions @@ -334,7 +344,10 @@ func (doc *Document) setAndParseType(field string, value interface{}) error { return err } - doc.setObject(core.OBJECT, field, subDoc) + err = doc.setObject(core.OBJECT, field, subDoc) + if err != nil { + return err + } default: return fmt.Errorf("Unhandled type in raw JSON: %v => %T", field, val) diff --git a/merkle/clock/clock.go b/merkle/clock/clock.go index 456acf80ff..bb1a4d1232 100644 --- a/merkle/clock/clock.go +++ b/merkle/clock/clock.go @@ -137,7 +137,7 @@ func (mc *MerkleClock) ProcessNode(ctx context.Context, ng core.NodeGetter, root if !hasHeads { // reached the bottom, at a leaf err := mc.headset.Add(ctx, root, rootPrio) if err != nil { - return nil, fmt.Errorf("error adding head %s : %w", root, err) + return nil, fmt.Errorf("error adding head (when reached the bottom) %s : %w", root, err) } return nil, nil } @@ -169,7 +169,13 @@ func (mc *MerkleClock) ProcessNode(ctx context.Context, ng core.NodeGetter, root if known { // we reached a non-head node in the known tree. // This means our root block is a new head - mc.headset.Add(ctx, root, rootPrio) + err := mc.headset.Add(ctx, root, rootPrio) + if err != nil { + log.Errorf("error adding head (when root is new head): %s : %w", root, err) + // OR should this also return like below comment?? + // return nil, fmt.Errorf("error adding head (when root is new head): %s : %w", root, err) + } + continue } diff --git a/merkle/clock/heads.go b/merkle/clock/heads.go index 559cf3b637..52ea236503 100644 --- a/merkle/clock/heads.go +++ b/merkle/clock/heads.go @@ -138,7 +138,13 @@ func (hh *heads) List(ctx context.Context) ([]cid.Cid, uint64, error) { if err != nil { return nil, 0, err } - defer results.Close() + + defer func() { + err := results.Close() + if err != nil { + log.Error(err) + } + }() heads := make([]cid.Cid, 0) var maxHeight uint64 diff --git a/merkle/crdt/composite.go b/merkle/crdt/composite.go index b33c7737bd..a503878764 100644 --- a/merkle/crdt/composite.go +++ b/merkle/crdt/composite.go @@ -11,6 +11,7 @@ package crdt import ( "context" + "log" "github.com/sourcenetwork/defradb/core" corecrdt "github.com/sourcenetwork/defradb/core/crdt" @@ -31,7 +32,10 @@ var ( ) func init() { - DefaultFactory.Register(core.COMPOSITE, &compFactoryFn) + err := DefaultFactory.Register(core.COMPOSITE, &compFactoryFn) + if err != nil { + log.Print(err) + } } // MerkleCompositeDAG is a MerkleCRDT implementation of the CompositeDAG diff --git a/merkle/crdt/lwwreg.go b/merkle/crdt/lwwreg.go index d22b2ff6d1..b57f607e2f 100644 --- a/merkle/crdt/lwwreg.go +++ b/merkle/crdt/lwwreg.go @@ -11,6 +11,7 @@ package crdt import ( "context" + "log" "github.com/sourcenetwork/defradb/core" corecrdt "github.com/sourcenetwork/defradb/core/crdt" @@ -31,7 +32,10 @@ var ( ) func init() { - DefaultFactory.Register(core.LWW_REGISTER, &lwwFactoryFn) + err := DefaultFactory.Register(core.LWW_REGISTER, &lwwFactoryFn) + if err != nil { + log.Print(err) + } } // MerkleLWWRegister is a MerkleCRDT implementation of the LWWRegister diff --git a/query/graphql/planner/datasource.go b/query/graphql/planner/datasource.go index 61c399af76..ee55c37b18 100644 --- a/query/graphql/planner/datasource.go +++ b/query/graphql/planner/datasource.go @@ -45,7 +45,10 @@ func (p *Planner) getCollectionScanPlan(collection string) (planSource, error) { } scan := p.Scan() - scan.initCollection(colDesc) + err = scan.initCollection(colDesc) + if err != nil { + return planSource{}, err + } return planSource{ plan: scan, diff --git a/query/graphql/planner/multi.go b/query/graphql/planner/multi.go index 44286fa04e..f7d24ceedf 100644 --- a/query/graphql/planner/multi.go +++ b/query/graphql/planner/multi.go @@ -12,6 +12,8 @@ package planner import ( "errors" + "log" + "github.com/sourcenetwork/defradb/core" ) @@ -117,10 +119,13 @@ func (p *parallelNode) Start() error { } func (p *parallelNode) Spans(spans core.Spans) { - p.applyToPlans(func(n planNode) error { + err := p.applyToPlans(func(n planNode) error { n.Spans(spans) return nil }) + if err != nil { + log.Print("applying spans to plans failed : ", err) + } } func (p *parallelNode) Close() error { @@ -173,7 +178,10 @@ func (p *parallelNode) nextAppend(index int, plan appendNode) (bool, error) { // pass the doc key as a reference through the spans interface spans := core.Spans{core.NewSpan(core.NewKey(key), core.Key{})} plan.Spans(spans) - plan.Init() + err := plan.Init() + if err != nil { + return false, err + } } else { return false, nil } diff --git a/query/graphql/planner/pipe.go b/query/graphql/planner/pipe.go index c78c596534..105494d044 100644 --- a/query/graphql/planner/pipe.go +++ b/query/graphql/planner/pipe.go @@ -66,7 +66,10 @@ func (n *pipeNode) Next() (bool, error) { } doc := n.source.Values() - n.docs.AddDoc(doc) + err = n.docs.AddDoc(doc) + if err != nil { + return false, err + } } n.docIndex++ return true, nil diff --git a/query/graphql/planner/planner.go b/query/graphql/planner/planner.go index 5cd9d45a25..30a7f075e0 100644 --- a/query/graphql/planner/planner.go +++ b/query/graphql/planner/planner.go @@ -212,7 +212,10 @@ func (p *Planner) expandSelectTopNodePlan(plan *selectTopNode, parentPlan *selec } if plan.limit != nil { - p.expandLimitPlan(plan, parentPlan) + err := p.expandLimitPlan(plan, parentPlan) + if err != nil { + return err + } } // wire up the render plan @@ -389,13 +392,17 @@ func (p *Planner) queryDocs(query *parser.Query) ([]map[string]interface{}, erro } if err = plan.Start(); err != nil { - plan.Close() + if err2 := (plan.Close()); err2 != nil { + fmt.Println(err2) + } return nil, err } var next bool if next, err = plan.Next(); err != nil || !next { - plan.Close() + if err2 := (plan.Close()); err2 != nil { + fmt.Println(err2) + } return nil, err } @@ -408,7 +415,9 @@ func (p *Planner) queryDocs(query *parser.Query) ([]map[string]interface{}, erro next, err = plan.Next() if err != nil { - plan.Close() + if err2 := (plan.Close()); err2 != nil { + fmt.Println(err2) + } return nil, err } diff --git a/query/graphql/planner/select.go b/query/graphql/planner/select.go index 76f07604d6..8a9b0a9daf 100644 --- a/query/graphql/planner/select.go +++ b/query/graphql/planner/select.go @@ -207,7 +207,8 @@ func (n *selectNode) initFields(parsed *parser.Select) ([]aggregateNode, error) if f.Name == parser.GroupFieldName { n.groupSelect = f } else { - n.addTypeIndexJoin(f) + // nolint:errcheck + n.addTypeIndexJoin(f) // @TODO: ISSUE#158 } } case *parser.Field: @@ -270,7 +271,8 @@ func (n *selectNode) joinAggregatedChild(parsed *parser.Select, field *parser.Fi subtype := &parser.Select{ Name: fieldName, } - n.addTypeIndexJoin(subtype) + // nolint:errcheck + n.addTypeIndexJoin(subtype) // @TODO: ISSUE#158 } } diff --git a/query/graphql/planner/type_join.go b/query/graphql/planner/type_join.go index 4c42620f5c..9df0e77f1c 100644 --- a/query/graphql/planner/type_join.go +++ b/query/graphql/planner/type_join.go @@ -289,7 +289,14 @@ func (n *typeJoinOne) valuesPrimary(doc map[string]interface{}) map[string]inter // do a point lookup with the new span (index key) n.subType.Spans(n.spans) - n.subType.Init() // re-initialize the sub type plan + + // re-initialize the sub type plan + if err := n.subType.Init(); err != nil { + // @todo pair up on the error handling / logging properly. + fmt.Println("sub-type initalization error with re-initalizing : %w", err) + return doc + } + // if we don't find any docs from our point span lookup // or if we encounter an error just return the base doc, // with an empty map for the subdoc @@ -417,7 +424,11 @@ func (n *typeJoinMany) Values() map[string]interface{} { } // reset scan node - n.subType.Init() + if err := n.subType.Init(); err != nil { + // @todo pair up on the error handling / logging properly. + fmt.Println("sub-type initalization error at scan node reset : %w", err) + } + for { next, err := n.subType.Next() if !next || err != nil { diff --git a/query/graphql/planner/update.go b/query/graphql/planner/update.go index a159f88b30..842b8028d2 100644 --- a/query/graphql/planner/update.go +++ b/query/graphql/planner/update.go @@ -76,7 +76,7 @@ func (n *updateNode) Next() (bool, error) { results, err = n.collection.UpdateWithFilter(n.p.ctx, n.filter, n.patch) } - fmt.Println("update node error:", err) + fmt.Println("update node error : ", err) if err != nil { return false, err } @@ -84,7 +84,11 @@ func (n *updateNode) Next() (bool, error) { // consume the updates into our valuesNode fmt.Println(results) for _, resKey := range results.DocKeys { - n.updateIter.docs.AddDoc(map[string]interface{}{"_key": resKey}) + err := n.updateIter.docs.AddDoc(map[string]interface{}{"_key": resKey}) + if err != nil { + fmt.Println("document adding error : ", err) + return false, err + } } n.isUpdating = false @@ -108,7 +112,11 @@ func (n *updateNode) Values() map[string]interface{} { spans := core.Spans{core.NewSpan(updatedDocKeyIndex, updatedDocKeyIndex.PrefixEnd())} n.results.Spans(spans) - n.results.Init() + + err := n.results.Init() + if err != nil { + fmt.Println("failure while initializing results : ", err) + } // get the next result based on our point lookup next, err := n.results.Next() diff --git a/query/graphql/schema/generate.go b/query/graphql/schema/generate.go index c9726791fe..1c6d26eb34 100644 --- a/query/graphql/schema/generate.go +++ b/query/graphql/schema/generate.go @@ -12,6 +12,7 @@ package schema import ( "errors" "fmt" + "log" "strings" "github.com/sourcenetwork/defradb/db/base" @@ -125,7 +126,11 @@ func (g *Generator) fromAST(document *ast.Document) ([]*gql.Object, error) { } for _, t := range generatedFilterBaseArgs { - g.manager.schema.AppendType(t) + err := g.manager.schema.AppendType(t) + if err != nil { + // Todo: better error handle + log.Printf("failure appending type while generating query type defs from an AST : %v", err) + } } // resolve types @@ -352,7 +357,13 @@ func (g *Generator) buildTypesFromAST(document *ast.Document) ([]*gql.Object, er if err != nil { return nil, err } - g.manager.Relations.RegisterSingle(relName, ttype.Name(), fType.Name, base.Meta_Relation_ONE) + + _, err = g.manager.Relations.RegisterSingle(relName, ttype.Name(), fType.Name, base.Meta_Relation_ONE) + if err != nil { + // Todo: better error handle + log.Printf("got error while registering single relation: %v", err) + } + case *gql.List: ltype := subobj.OfType // register the relation @@ -360,7 +371,12 @@ func (g *Generator) buildTypesFromAST(document *ast.Document) ([]*gql.Object, er if err != nil { return nil, err } - g.manager.Relations.RegisterSingle(relName, ltype.Name(), fType.Name, base.Meta_Relation_MANY) + + _, err = g.manager.Relations.RegisterSingle(relName, ltype.Name(), fType.Name, base.Meta_Relation_MANY) + if err != nil { + // Todo: better error handle + log.Printf("got error while registering single relation: %v", err) + } } fType.Type = ttype @@ -514,7 +530,12 @@ func (g *Generator) genSumFieldConfig(obj *gql.Object) gql.Field { return fields, nil }) sumType = gql.NewInputObject(inputCfg) - g.manager.schema.AppendType(sumType) //this might resolve the thunk? Race issue? + + //this might resolve the thunk? Race issue? + err := g.manager.schema.AppendType(sumType) + if err != nil { + log.Printf("failure appending sumType : %v", err) + } field := gql.Field{ Name: parser.SumFieldName, @@ -850,10 +871,25 @@ func (g *Generator) genTypeQueryableFieldList(obj *gql.Object, config queryInput name := strings.ToLower(obj.Name()) // add the generated types to the type map - g.manager.schema.AppendType(config.filter) - g.manager.schema.AppendType(config.groupBy) - g.manager.schema.AppendType(config.having) - g.manager.schema.AppendType(config.order) + if err := g.manager.schema.AppendType(config.filter); err != nil { + // Todo: better error handle + log.Printf("failure appending runtime schema - filter: %v", err) + } + + if err := g.manager.schema.AppendType(config.groupBy); err != nil { + // Todo: better error handle + log.Printf("failure appending runtime schema - groupBy: %v", err) + } + + if err := g.manager.schema.AppendType(config.having); err != nil { + // Todo: better error handle + log.Printf("failure appending runtime schema - having: %v", err) + } + + if err := g.manager.schema.AppendType(config.order); err != nil { + // Todo: better error handle + log.Printf("failure appending runtime schema - order: %v", err) + } field := &gql.Field{ // @todo: Handle collection name from @collection directive diff --git a/store/blockstore.go b/store/blockstore.go index 681da8464a..617f0a01f2 100644 --- a/store/blockstore.go +++ b/store/blockstore.go @@ -147,7 +147,7 @@ func (bs *bstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { output := make(chan cid.Cid, dsq.KeysOnlyBufSize) go func() { defer func() { - res.Close() // ensure exit (signals early exit, too) + log.Error(res.Close()) // ensure exit (signals early exit, too) close(output) }()