z5labs/gogm

obscure errors

bejaneps opened this issue · 3 comments

Hi, recently I started working with gogm package and got stuck with some obscure errors that pop out on some of the actions and not on others. So, this are list of the errors that pop out and aren't very well documented and don't report the issue well:

  1. Invalid handle (comes from Query function)
  2. Invalid struct size: 191 (comes from SaveDepth function, size number changes from time to time)
  3. read tcp 10.8.0.58:47700->128.199.56.38:6687: read: connection reset by peer (comes from Query function, I know that it's related to neo4j connection, but not sure why it's happening)
  4. Unconsumed data (comes from Query function)
  5. EOF (comes from Query function)
  6. Map key is not string type: int64 (comes from Query functions, from BaseNode.LoadMap field)

After doing some research, I've found out that most of the errors are just being redirected from neo4j-go-driver package, so my enhancement proposal is to add more context related info to the errors (like with errors.Wrapf or errors.WithMessagef), because it's really hard to understand the meaning of errors or why they are happening.

This are the queries that I run:

errors: 1, 3, 4, 5, 6)

MATCH (n:ReferenceInstantValue {name:"{{.Name}}", beginReferencePeriod:"{{.BeginReferencePeriod}}", endReferencePeriod:"{{.EndReferencePeriod}}", uniqId:"{{.UniqID}}"})-[:PROVIDED_BY]->(sensor) WHERE sensor.name="{{.Sensor.Name}}" RETURN n.uniqId, n.endReferencePeriod, n.beginReferencePeriod, n.startVersion, n.name, n.endVersion, n.canonicalValuesNames, n.fieldsNames, n.tableName

errors: 2

MATCH (n:ReferenceInstantValue {name:"{{.Name}}", uniqId:"{{.UniqID}}"}),(m:Sensor {name:"{{.Sensor.Name}}"}) WHERE n.beginReferencePeriod="{{.BeginReferencePeriod}}" AND n.endReferencePeriod="{{.EndReferencePeriod}}" AND m.uniqId="{{.Sensor.UniqID}}" CREATE (n)-[r:PROVIDED_BY]->(m) RETURN type(r)

If this explanation doesn't help a lot, please comment on this issue, and I will post more information.

Are you using go templates to inject params into your cypher query?

@erictg Hi, yes, I use templates. Does it make any difference ?

I would try using neo4j parameters

assuming a session has already been created, it would be something like this:

var toWrite SomeRegisteredNode
sess.Query("match (n:SomeNode{some_id:$id}) return n", map[string]interface{}{
   "id": "some id"
}, &toWrite)

The map is where you can define your params and you can represent them within the query with $. GOGM using the driver under the hood will serialize the param. This works with most golang built in types and slices of said types.

This accomplishes what you're trying to do without having to worry about compiling the go templates and ensuring type conversion is correct