@@ -101,22 +101,8 @@ func newConn(c *Connector, s table.ClosableSession, opts ...connOption) *conn {
101101 return cc
102102}
103103
104- func (c * conn ) checkClosed (err error ) error {
105- if err = badconn .Map (err ); xerrors .Is (err , driver .ErrBadConn ) {
106- atomic .StoreUint32 (& c .closed , 1 )
107- }
108- return err
109- }
110-
111104func (c * conn ) isReady () bool {
112- if atomic .LoadUint32 (& c .closed ) == 1 {
113- return true
114- }
115- if c .session .Status () != table .SessionReady {
116- atomic .StoreUint32 (& c .closed , 1 )
117- return true
118- }
119- return false
105+ return c .session .Status () == table .SessionReady
120106}
121107
122108func (conn ) CheckNamedValue (v * driver.NamedValue ) (err error ) {
@@ -129,7 +115,7 @@ func (c *conn) PrepareContext(ctx context.Context, query string) (_ driver.Stmt,
129115 onDone (err )
130116 }()
131117 if ! c .isReady () {
132- return nil , errNotReadyConn
118+ return nil , badconn . Map ( xerrors . WithStackTrace ( errNotReadyConn ))
133119 }
134120 return & stmt {
135121 conn : c ,
@@ -162,38 +148,38 @@ func (c *conn) execContext(ctx context.Context, query string, args []driver.Name
162148 dataQueryOptions (ctx )... ,
163149 )
164150 if err != nil {
165- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
151+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
166152 }
167153 defer func () {
168154 _ = res .Close ()
169155 }()
170156 if err = res .NextResultSetErr (ctx ); ! xerrors .Is (err , nil , io .EOF ) {
171- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
157+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
172158 }
173159 if err = res .Err (); err != nil {
174- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
160+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
175161 }
176162 return driver .ResultNoRows , nil
177163 case SchemeQueryMode :
178164 err = c .session .ExecuteSchemeQuery (ctx , query )
179165 if err != nil {
180- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
166+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
181167 }
182168 return driver .ResultNoRows , nil
183169 case ScriptingQueryMode :
184170 var res result.StreamResult
185171 res , err = c .connector .connection .Scripting ().StreamExecute (ctx , query , toQueryParams (args ))
186172 if err != nil {
187- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
173+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
188174 }
189175 defer func () {
190176 _ = res .Close ()
191177 }()
192178 if err = res .NextResultSetErr (ctx ); ! xerrors .Is (err , nil , io .EOF ) {
193- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
179+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
194180 }
195181 if err = res .Err (); err != nil {
196- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
182+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
197183 }
198184 return driver .ResultNoRows , nil
199185 default :
@@ -203,7 +189,7 @@ func (c *conn) execContext(ctx context.Context, query string, args []driver.Name
203189
204190func (c * conn ) ExecContext (ctx context.Context , query string , args []driver.NamedValue ) (_ driver.Result , err error ) {
205191 if ! c .isReady () {
206- return nil , errNotReadyConn
192+ return nil , badconn . Map ( xerrors . WithStackTrace ( errNotReadyConn ))
207193 }
208194 if c .currentTx != nil {
209195 return c .currentTx .ExecContext (ctx , query , args )
@@ -213,7 +199,7 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name
213199
214200func (c * conn ) QueryContext (ctx context.Context , query string , args []driver.NamedValue ) (_ driver.Rows , err error ) {
215201 if ! c .isReady () {
216- return nil , errNotReadyConn
202+ return nil , badconn . Map ( xerrors . WithStackTrace ( errNotReadyConn ))
217203 }
218204 if c .currentTx != nil {
219205 return c .currentTx .QueryContext (ctx , query , args )
@@ -245,10 +231,10 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam
245231 dataQueryOptions (ctx )... ,
246232 )
247233 if err != nil {
248- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
234+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
249235 }
250236 if err = res .Err (); err != nil {
251- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
237+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
252238 }
253239 return & rows {
254240 conn : c ,
@@ -262,10 +248,10 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam
262248 scanQueryOptions (ctx )... ,
263249 )
264250 if err != nil {
265- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
251+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
266252 }
267253 if err = res .Err (); err != nil {
268- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
254+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
269255 }
270256 return & rows {
271257 conn : c ,
@@ -275,7 +261,7 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam
275261 var exp table.DataQueryExplanation
276262 exp , err = c .session .Explain (ctx , query )
277263 if err != nil {
278- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
264+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
279265 }
280266 return & single {
281267 values : []sql.NamedArg {
@@ -287,10 +273,10 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam
287273 var res result.StreamResult
288274 res , err = c .connector .connection .Scripting ().StreamExecute (ctx , query , toQueryParams (args ))
289275 if err != nil {
290- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
276+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
291277 }
292278 if err = res .Err (); err != nil {
293- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
279+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
294280 }
295281 return & rows {
296282 conn : c ,
@@ -307,10 +293,10 @@ func (c *conn) Ping(ctx context.Context) (err error) {
307293 onDone (err )
308294 }()
309295 if ! c .isReady () {
310- return errNotReadyConn
296+ return badconn . Map ( xerrors . WithStackTrace ( errNotReadyConn ))
311297 }
312298 if err = c .session .KeepAlive (ctx ); err != nil {
313- return c . checkClosed (xerrors .WithStackTrace (err ))
299+ return badconn . Map (xerrors .WithStackTrace (err ))
314300 }
315301 return nil
316302}
@@ -327,7 +313,7 @@ func (c *conn) Close() (err error) {
327313 }
328314 return nil
329315 }
330- return errClosedConn
316+ return badconn . Map ( xerrors . WithStackTrace ( errClosedConn ))
331317}
332318
333319func (c * conn ) Prepare (string ) (driver.Stmt , error ) {
@@ -345,7 +331,7 @@ func (c *conn) BeginTx(ctx context.Context, txOptions driver.TxOptions) (_ drive
345331 onDone (transaction , err )
346332 }()
347333 if ! c .isReady () {
348- return nil , errNotReadyConn
334+ return nil , badconn . Map ( xerrors . WithStackTrace ( errNotReadyConn ))
349335 }
350336 if c .currentTx != nil {
351337 return nil , xerrors .WithStackTrace (
@@ -359,7 +345,7 @@ func (c *conn) BeginTx(ctx context.Context, txOptions driver.TxOptions) (_ drive
359345 }
360346 transaction , err = c .session .BeginTransaction (ctx , table .TxSettings (txc ))
361347 if err != nil {
362- return nil , c . checkClosed (xerrors .WithStackTrace (err ))
348+ return nil , badconn . Map (xerrors .WithStackTrace (err ))
363349 }
364350 c .currentTx = & tx {
365351 conn : c ,
0 commit comments