Skip to content

Commit

Permalink
Merge pull request RedisGraph#14 from RedisGraph/runtime-errors
Browse files Browse the repository at this point in the history
handle query runtime errors
  • Loading branch information
swilly22 authored Sep 12, 2019
2 parents eb62d44 + f25c6f8 commit 9bef240
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
14 changes: 12 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,19 @@ func TestCreateQuery(t *testing.T) {
assert.Equal(t, w.Label, "WorkPlace", "Unexpected node label.")
}

func TestArray(t *testing.T) {
func TestErrorReporting(t *testing.T) {
q := "RETURN toupper(5)"
res, err := graph.Query(q)
assert.Nil(t, res)
assert.NotNil(t, err)

q = "MATCH (p:Person) RETURN toupper(p.age)"
res, err = graph.Query(q)
assert.Nil(t, res)
assert.NotNil(t, err)
}

func TestArray(t *testing.T) {
graph.Flush()
graph.Query("MATCH (n) DELETE n")

Expand Down Expand Up @@ -192,5 +203,4 @@ func TestArray(t *testing.T) {
assert.Equal(t, b.GetProperty("name"), resB.GetProperty("name"), "Unexpected property value.")
assert.Equal(t, b.GetProperty("age"), resB.GetProperty("age"), "Unexpected property value.")
assert.Equal(t, b.GetProperty("array"), resB.GetProperty("array"), "Unexpected property value.")

}
3 changes: 1 addition & 2 deletions graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ func (g *Graph) Query(q string) (*QueryResult, error) {
return nil, err
}

qr := QueryResultNew(g, r)
return qr, nil
return QueryResultNew(g, r)
}

// Merge pattern
Expand Down
10 changes: 8 additions & 2 deletions query_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type QueryResult struct {
graph *Graph
}

func QueryResultNew(g *Graph, response interface{}) *QueryResult {
func QueryResultNew(g *Graph, response interface{}) (*QueryResult, error) {
qr := &QueryResult{
results: nil,
statistics: nil,
Expand All @@ -68,14 +68,20 @@ func QueryResultNew(g *Graph, response interface{}) *QueryResult {
}

r, _ := redis.Values(response, nil)

// Check to see if we're encountered a run-time error.
if err, ok := r[len(r)-1].(redis.Error); ok {
return nil, err
}

if len(r) == 1 {
qr.parseStatistics(r[0])
} else {
qr.parseResults(r)
qr.parseStatistics(r[2])
}

return qr
return qr, nil
}

func (qr *QueryResult) Empty() bool {
Expand Down

0 comments on commit 9bef240

Please sign in to comment.