From 9023b6914a4e20bd42436ee29219058e973b0156 Mon Sep 17 00:00:00 2001 From: Jerome Touffe-Blin Date: Mon, 18 Apr 2016 21:27:52 +1000 Subject: [PATCH] #311 - Fix panic error when session is nil or not connected --- query.go | 4 ++++ query_test.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/query.go b/query.go index 1bd88a36..8c04dbce 100644 --- a/query.go +++ b/query.go @@ -242,6 +242,10 @@ func (t Term) Run(s *Session, optArgs ...RunOpts) (*Cursor, error) { opts = optArgs[0].toMap() } + if s == nil || !s.IsConnected() { + return nil, ErrConnectionClosed + } + q, err := s.newQuery(t, opts) if err != nil { return nil, err diff --git a/query_test.go b/query_test.go index 486be131..93372505 100644 --- a/query_test.go +++ b/query_test.go @@ -65,3 +65,17 @@ func (s *RethinkSuite) TestQueryRunRawTime(c *test.C) { c.Assert(response["$reql_type$"], test.NotNil) c.Assert(response["$reql_type$"], test.Equals, "TIME") } + +func (s *RethinkSuite) TestQueryRunNil(c *test.C) { + res, err := Expr("Test").Run(nil) + c.Assert(res, test.IsNil) + c.Assert(err, test.NotNil) + c.Assert(err, test.Equals, ErrConnectionClosed) +} + +func (s *RethinkSuite) TestQueryRunNotConnected(c *test.C) { + res, err := Expr("Test").Run(&Session{}) + c.Assert(res, test.IsNil) + c.Assert(err, test.NotNil) + c.Assert(err, test.Equals, ErrConnectionClosed) +} \ No newline at end of file