diff --git a/client_test.go b/client_test.go index 380be50..22aa1bf 100644 --- a/client_test.go +++ b/client_test.go @@ -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") @@ -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.") - } diff --git a/graph.go b/graph.go index bba48fd..85f7f4c 100644 --- a/graph.go +++ b/graph.go @@ -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 diff --git a/query_result.go b/query_result.go index 0d35c31..fa3d53b 100644 --- a/query_result.go +++ b/query_result.go @@ -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, @@ -68,6 +68,12 @@ 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 { @@ -75,7 +81,7 @@ func QueryResultNew(g *Graph, response interface{}) *QueryResult { qr.parseStatistics(r[2]) } - return qr + return qr, nil } func (qr *QueryResult) Empty() bool {