From c3a9966b06f4d9563b0ff25045c5b080cf6b6906 Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Mon, 9 Mar 2015 13:35:07 -0400 Subject: [PATCH] add nil check --- tx.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tx.go b/tx.go index ac00ff1..aa5f4f4 100644 --- a/tx.go +++ b/tx.go @@ -2,6 +2,7 @@ package jet import ( "database/sql" + "errors" ) // Tx represents a transaction instance. @@ -21,6 +22,9 @@ func (tx *Tx) Query(query string, args ...interface{}) Runnable { // Exec calls Exec on the underlying sql.Tx. func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error) { + if tx == nil || tx.tx == nil { + return nil, errors.New("jet: Exec called on nil transaction") + } return tx.tx.Exec(query, args...) }