cayleygraph / cayley

An open-source graph database
https://cayley.io
Apache License 2.0
14.8k stars 1.25k forks source link

Code quality: NameOf and ValueOf should return errors #958

Closed paralin closed 3 years ago

paralin commented 3 years ago

Throughout the code there are calls to ValueOf() and NameOf() on the QuadStore. The QuadStore currently returns a single value for these functions without an error, but internally the QuadStore might run into some errors when processing the value. This hack is clearly identified in the code: rather than return the error, it's just logged, i.e.:

clog.Errorf("Error in NameOf, context is nil, graph not correctly initialised")
return nil

If the QuadStore has an error while processing ValueOf or NameOf, the returned value will be nil which might lead to many types of undefined behavior - such as queries returning "nil" for one field of a Quad.

paralin commented 3 years ago

Similarly QuadDirection should return an error

paralin commented 3 years ago

I refactored the code to add error returns values to those funcs: https://github.com/cayleygraph/cayley/pull/959