Skip to content

Commit 9023b69

Browse files
committed
#311 - Fix panic error when session is nil or not connected
1 parent ad8c73f commit 9023b69

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

query.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ func (t Term) Run(s *Session, optArgs ...RunOpts) (*Cursor, error) {
242242
opts = optArgs[0].toMap()
243243
}
244244

245+
if s == nil || !s.IsConnected() {
246+
return nil, ErrConnectionClosed
247+
}
248+
245249
q, err := s.newQuery(t, opts)
246250
if err != nil {
247251
return nil, err

query_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,17 @@ func (s *RethinkSuite) TestQueryRunRawTime(c *test.C) {
6565
c.Assert(response["$reql_type$"], test.NotNil)
6666
c.Assert(response["$reql_type$"], test.Equals, "TIME")
6767
}
68+
69+
func (s *RethinkSuite) TestQueryRunNil(c *test.C) {
70+
res, err := Expr("Test").Run(nil)
71+
c.Assert(res, test.IsNil)
72+
c.Assert(err, test.NotNil)
73+
c.Assert(err, test.Equals, ErrConnectionClosed)
74+
}
75+
76+
func (s *RethinkSuite) TestQueryRunNotConnected(c *test.C) {
77+
res, err := Expr("Test").Run(&Session{})
78+
c.Assert(res, test.IsNil)
79+
c.Assert(err, test.NotNil)
80+
c.Assert(err, test.Equals, ErrConnectionClosed)
81+
}

0 commit comments

Comments
 (0)