northwesternmutual / grammes

A Go package built to communicate with Apache TinkerPop™ Graph computing framework using Gremlin; a graph traversal language used by graph databases such as JanusGraph®, MS Cosmos DB, AWS Neptune, and DataStax® Enterprise Graph.
Apache License 2.0
125 stars 45 forks source link

Gremlin query returns error but response message doesn't showing #2

Closed learntechpuzz closed 5 years ago

learntechpuzz commented 5 years ago

gremconnect\response.go line no: 60 //resp.Data = err // Use the Data field as a vehicle for the error. Let take a example: Try to execute query "ExecuteStringQuery" which possibly returns "Edge is already exists" at the Gremlin Server but it is not handled properly in response []byte

Suggestion: resp.Data = message // Changes to handle error messages.

damienfamed75 commented 5 years ago

Hello,

I apologize for the late response. Are you proposing that grammes should handle errors that do not correspond to documented error codes from the Gremlin server? From how I'm reading this it seems you'd like this response to be handled as an error, but is just a warning of sorts.

I'm reading: http://tinkerpop.apache.org/javadocs/3.2.4/full/index.html?org/apache/tinkerpop/gremlin/driver/message/ResponseStatusCode.html for all the error codes that are handled by the client.

damienfamed75 commented 5 years ago

After re-reading I believe what you are informing me about is that the error message isn't inherently available using just the grammes client.

https://github.com/northwesternmutual/grammes/blob/5585b5a7cc9d39f14445123d8d8bcd224d4e668f/response.go#L53

In this file you can see any error messages are returned into the errs channel which is accessible via the grammes concurrent error handling channel when setting up the client.

I apologize for not providing an example in the examples/ directory. I must've deleted it at some point when cleaning up the repo. I'll re-add it in there. For now I will just provide one...

What I suggest doing is:

func main() {
    // Create an error channel to handle all error handling concurrently.
    errs := make(chan error)
    go func(chan error) {
        err := <-errs
        fmt.Printf("error with grammes client: %v\n", err)
    }(errs)

    // Use the WithErrorChannel ClientConfiguration to use the errors channel.
    _, err := grammes.DialWithWebSocket("ws://127.0.0.1:8182", grammes.WithErrorChannel(errs))

    // ...more code
}

Hope this helps.