@@ -48,13 +48,13 @@ where
48
48
Conn : ' static + DieselConnection + R2D2Connection ,
49
49
Self : Send + Sized + ' static ,
50
50
{
51
- async fn ping_async ( & mut self ) -> Result < ( ) , RunError < DieselError > > {
51
+ async fn ping_async ( & mut self ) -> Result < ( ) , RunError > {
52
52
self . as_async_conn ( ) . run ( |conn| conn. ping ( ) ) . await
53
53
}
54
54
55
55
async fn is_broken_async ( & mut self ) -> bool {
56
56
self . as_async_conn ( )
57
- . run ( |conn| Ok :: < bool , ( ) > ( conn. is_broken ( ) ) )
57
+ . run ( |conn| Ok :: < bool , _ > ( conn. is_broken ( ) ) )
58
58
. await
59
59
. unwrap ( )
60
60
}
@@ -75,42 +75,36 @@ where
75
75
fn as_async_conn ( & self ) -> & Connection < Conn > ;
76
76
77
77
/// Runs the function `f` in an context where blocking is safe.
78
- async fn run < R , E , Func > ( & self , f : Func ) -> Result < R , RunError < E > >
78
+ async fn run < R , Func > ( & self , f : Func ) -> Result < R , RunError >
79
79
where
80
80
R : Send + ' static ,
81
- E : Send + ' static ,
82
- Func : FnOnce ( & mut Conn ) -> Result < R , E > + Send + ' static ,
81
+ Func : FnOnce ( & mut Conn ) -> Result < R , DieselError > + Send + ' static ,
83
82
{
84
83
let connection = self . get_owned_connection ( ) ;
85
84
connection. run_with_connection ( f) . await
86
85
}
87
86
88
87
#[ doc( hidden) ]
89
- async fn run_with_connection < R , E , Func > ( self , f : Func ) -> Result < R , RunError < E > >
88
+ async fn run_with_connection < R , Func > ( self , f : Func ) -> Result < R , RunError >
90
89
where
91
90
R : Send + ' static ,
92
- E : Send + ' static ,
93
- Func : FnOnce ( & mut Conn ) -> Result < R , E > + Send + ' static ,
91
+ Func : FnOnce ( & mut Conn ) -> Result < R , DieselError > + Send + ' static ,
94
92
{
95
93
handle_spawn_blocking_error ( spawn_blocking ( move || f ( & mut * self . as_sync_conn ( ) ) ) . await )
96
94
}
97
95
98
96
#[ doc( hidden) ]
99
- async fn run_with_shared_connection < R , E , Func > (
100
- self : & Arc < Self > ,
101
- f : Func ,
102
- ) -> Result < R , RunError < E > >
97
+ async fn run_with_shared_connection < R , Func > ( self : & Arc < Self > , f : Func ) -> Result < R , RunError >
103
98
where
104
99
R : Send + ' static ,
105
- E : Send + ' static ,
106
- Func : FnOnce ( & mut Conn ) -> Result < R , E > + Send + ' static ,
100
+ Func : FnOnce ( & mut Conn ) -> Result < R , DieselError > + Send + ' static ,
107
101
{
108
102
let conn = self . clone ( ) ;
109
103
handle_spawn_blocking_error ( spawn_blocking ( move || f ( & mut * conn. as_sync_conn ( ) ) ) . await )
110
104
}
111
105
112
106
#[ doc( hidden) ]
113
- async fn transaction_depth ( & self ) -> Result < u32 , RunError < DieselError > > {
107
+ async fn transaction_depth ( & self ) -> Result < u32 , RunError > {
114
108
let conn = self . get_owned_connection ( ) ;
115
109
116
110
Self :: run_with_connection ( conn, |conn| {
@@ -130,9 +124,9 @@ where
130
124
// This method is a wrapper around that call, with validation that
131
125
// we're actually issuing the BEGIN statement here.
132
126
#[ doc( hidden) ]
133
- async fn start_transaction ( self : & Arc < Self > ) -> Result < ( ) , RunError < DieselError > > {
127
+ async fn start_transaction ( self : & Arc < Self > ) -> Result < ( ) , RunError > {
134
128
if self . transaction_depth ( ) . await ? != 0 {
135
- return Err ( RunError :: User ( DieselError :: AlreadyInTransaction ) ) ;
129
+ return Err ( RunError :: DieselError ( DieselError :: AlreadyInTransaction ) ) ;
136
130
}
137
131
self . run_with_shared_connection ( |conn| Conn :: TransactionManager :: begin_transaction ( conn) )
138
132
. await ?;
@@ -145,11 +139,11 @@ where
145
139
// This method is a wrapper around that call, with validation that
146
140
// we're actually issuing our first SAVEPOINT here.
147
141
#[ doc( hidden) ]
148
- async fn add_retry_savepoint ( self : & Arc < Self > ) -> Result < ( ) , RunError < DieselError > > {
142
+ async fn add_retry_savepoint ( self : & Arc < Self > ) -> Result < ( ) , RunError > {
149
143
match self . transaction_depth ( ) . await ? {
150
- 0 => return Err ( RunError :: User ( DieselError :: NotInTransaction ) ) ,
144
+ 0 => return Err ( RunError :: DieselError ( DieselError :: NotInTransaction ) ) ,
151
145
1 => ( ) ,
152
- _ => return Err ( RunError :: User ( DieselError :: AlreadyInTransaction ) ) ,
146
+ _ => return Err ( RunError :: DieselError ( DieselError :: AlreadyInTransaction ) ) ,
153
147
} ;
154
148
155
149
self . run_with_shared_connection ( |conn| Conn :: TransactionManager :: begin_transaction ( conn) )
@@ -158,14 +152,14 @@ where
158
152
}
159
153
160
154
#[ doc( hidden) ]
161
- async fn commit_transaction ( self : & Arc < Self > ) -> Result < ( ) , RunError < DieselError > > {
155
+ async fn commit_transaction ( self : & Arc < Self > ) -> Result < ( ) , RunError > {
162
156
self . run_with_shared_connection ( |conn| Conn :: TransactionManager :: commit_transaction ( conn) )
163
157
. await ?;
164
158
Ok ( ( ) )
165
159
}
166
160
167
161
#[ doc( hidden) ]
168
- async fn rollback_transaction ( self : & Arc < Self > ) -> Result < ( ) , RunError < DieselError > > {
162
+ async fn rollback_transaction ( self : & Arc < Self > ) -> Result < ( ) , RunError > {
169
163
self . run_with_shared_connection ( |conn| {
170
164
Conn :: TransactionManager :: rollback_transaction ( conn)
171
165
} )
@@ -184,10 +178,10 @@ where
184
178
& ' a self ,
185
179
f : Func ,
186
180
retry : RetryFunc ,
187
- ) -> Result < R , RunError < DieselError > >
181
+ ) -> Result < R , RunError >
188
182
where
189
183
R : Any + Send + ' static ,
190
- Fut : FutureExt < Output = Result < R , RunError < DieselError > > > + Send ,
184
+ Fut : FutureExt < Output = Result < R , RunError > > + Send ,
191
185
Func : ( Fn ( Connection < Conn > ) -> Fut ) + Send + Sync ,
192
186
RetryFut : FutureExt < Output = bool > + Send ,
193
187
RetryFunc : Fn ( ) -> RetryFut + Send + Sync ,
@@ -220,13 +214,11 @@ where
220
214
#[ cfg( feature = "cockroach" ) ]
221
215
async fn transaction_async_with_retry_inner (
222
216
& self ,
223
- f : & ( dyn Fn (
224
- Connection < Conn > ,
225
- ) -> BoxFuture < ' _ , Result < Box < dyn Any + Send > , RunError < DieselError > > >
217
+ f : & ( dyn Fn ( Connection < Conn > ) -> BoxFuture < ' _ , Result < Box < dyn Any + Send > , RunError > >
226
218
+ Send
227
219
+ Sync ) ,
228
220
retry : & ( dyn Fn ( ) -> BoxFuture < ' _ , bool > + Send + Sync ) ,
229
- ) -> Result < Box < dyn Any + Send > , RunError < DieselError > > {
221
+ ) -> Result < Box < dyn Any + Send > , RunError > {
230
222
// Check out a connection once, and use it for the duration of the
231
223
// operation.
232
224
let conn = Arc :: new ( self . get_owned_connection ( ) ) ;
@@ -264,7 +256,7 @@ where
264
256
// We're still in the transaction, but we at least
265
257
// tried to ROLLBACK to our savepoint.
266
258
let retried = match & err {
267
- RunError :: User ( err) => retryable_error ( err) && retry ( ) . await ,
259
+ RunError :: DieselError ( err) => retryable_error ( err) && retry ( ) . await ,
268
260
RunError :: RuntimeShutdown => false ,
269
261
} ;
270
262
if retried {
@@ -282,7 +274,7 @@ where
282
274
Self :: commit_transaction ( & conn) . await ?;
283
275
return Ok ( value) ;
284
276
}
285
- Err ( RunError :: User ( user_error) ) => {
277
+ Err ( RunError :: DieselError ( user_error) ) => {
286
278
// The user-level operation failed: ROLLBACK to the retry
287
279
// savepoint.
288
280
if let Err ( first_rollback_err) = Self :: rollback_transaction ( & conn) . await {
@@ -302,7 +294,7 @@ where
302
294
303
295
// If we aren't retrying, ROLLBACK the BEGIN statement too.
304
296
return match Self :: rollback_transaction ( & conn) . await {
305
- Ok ( ( ) ) => Err ( RunError :: User ( user_error) ) ,
297
+ Ok ( ( ) ) => Err ( RunError :: DieselError ( user_error) ) ,
306
298
Err ( err) => Err ( err) ,
307
299
} ;
308
300
}
@@ -321,7 +313,7 @@ where
321
313
async fn transaction_async < R , E , Func , Fut , ' a > ( & ' a self , f : Func ) -> Result < R , E >
322
314
where
323
315
R : Send + ' static ,
324
- E : From < RunError < DieselError > > + Send + ' static ,
316
+ E : From < RunError > + Send + ' static ,
325
317
Fut : Future < Output = Result < R , E > > + Send ,
326
318
Func : FnOnce ( Connection < Conn > ) -> Fut + Send ,
327
319
{
@@ -354,7 +346,7 @@ where
354
346
> ,
355
347
) -> Result < Box < dyn Any + Send > , E >
356
348
where
357
- E : From < RunError < DieselError > > + Send + ' static ,
349
+ E : From < RunError > + Send + ' static ,
358
350
{
359
351
// Check out a connection once, and use it for the duration of the
360
352
// operation.
@@ -365,15 +357,8 @@ where
365
357
//
366
358
// However, it modifies all callsites to instead issue
367
359
// known-to-be-synchronous operations from an asynchronous context.
368
- conn. run_with_shared_connection ( |conn| {
369
- Conn :: TransactionManager :: begin_transaction ( conn)
370
- . map_err ( |err| E :: from ( RunError :: User ( err) ) )
371
- } )
372
- . await
373
- . map_err ( |err| match err {
374
- RunError :: User ( err) => err,
375
- RunError :: RuntimeShutdown => RunError :: RuntimeShutdown . into ( ) ,
376
- } ) ?;
360
+ conn. run_with_shared_connection ( |conn| Conn :: TransactionManager :: begin_transaction ( conn) )
361
+ . await ?;
377
362
378
363
// TODO: The ideal interface would pass the "async_conn" object to the
379
364
// underlying function "f" by reference.
@@ -390,42 +375,29 @@ where
390
375
let async_conn = Connection ( Self :: as_async_conn ( & conn) . 0 . clone ( ) ) ;
391
376
match f ( async_conn) . await {
392
377
Ok ( value) => {
393
- match conn
394
- . run_with_shared_connection ( |conn| {
395
- Conn :: TransactionManager :: commit_transaction ( conn)
396
- . map_err ( |err| E :: from ( RunError :: User ( err) ) )
397
- } )
398
- . await
399
- {
400
- Ok ( ( ) ) => Ok ( value) ,
401
- // XXX: we should try to roll this back
402
- Err ( RunError :: User ( err) ) => Err ( err) ,
403
- Err ( RunError :: RuntimeShutdown ) => Err ( RunError :: RuntimeShutdown . into ( ) ) ,
404
- }
378
+ conn. run_with_shared_connection ( |conn| {
379
+ Conn :: TransactionManager :: commit_transaction ( conn)
380
+ } )
381
+ . await ?;
382
+ Ok ( value)
405
383
}
406
384
Err ( user_error) => {
407
- match conn
408
- . run_with_shared_connection ( |conn| {
409
- Conn :: TransactionManager :: rollback_transaction ( conn)
410
- . map_err ( |err| E :: from ( RunError :: User ( err) ) )
411
- } )
412
- . await
413
- {
414
- Ok ( ( ) ) => Err ( user_error) ,
415
- Err ( RunError :: User ( err) ) => Err ( err) ,
416
- Err ( RunError :: RuntimeShutdown ) => Err ( RunError :: RuntimeShutdown . into ( ) ) ,
417
- }
385
+ conn. run_with_shared_connection ( |conn| {
386
+ Conn :: TransactionManager :: rollback_transaction ( conn)
387
+ } )
388
+ . await ?;
389
+ Err ( user_error)
418
390
}
419
391
}
420
392
}
421
393
}
422
394
423
- fn handle_spawn_blocking_error < T , E > (
424
- result : Result < Result < T , E > , JoinError > ,
425
- ) -> Result < T , RunError < E > > {
395
+ fn handle_spawn_blocking_error < T > (
396
+ result : Result < Result < T , DieselError > , JoinError > ,
397
+ ) -> Result < T , RunError > {
426
398
match result {
427
399
Ok ( Ok ( v) ) => Ok ( v) ,
428
- Ok ( Err ( err) ) => Err ( RunError :: User ( err) ) ,
400
+ Ok ( Err ( err) ) => Err ( RunError :: DieselError ( err) ) ,
429
401
Err ( err) => {
430
402
if err. is_cancelled ( ) {
431
403
// The only way a spawn_blocking task can be marked cancelled
@@ -438,7 +410,11 @@ fn handle_spawn_blocking_error<T, E>(
438
410
} else {
439
411
// Not possible to reach this as of Tokio 1.40, but maybe in
440
412
// future versions.
441
- panic ! ( "unexpected JoinError: {:?}" , err) ;
413
+ panic ! (
414
+ "unexpected JoinError, did a new version of Tokio add \
415
+ a source other than panics and cancellations? {:?}",
416
+ err
417
+ ) ;
442
418
}
443
419
}
444
420
}
@@ -450,26 +426,26 @@ pub trait AsyncRunQueryDsl<Conn, AsyncConn>
450
426
where
451
427
Conn : ' static + DieselConnection ,
452
428
{
453
- async fn execute_async ( self , asc : & AsyncConn ) -> Result < usize , RunError < DieselError > >
429
+ async fn execute_async ( self , asc : & AsyncConn ) -> Result < usize , RunError >
454
430
where
455
431
Self : ExecuteDsl < Conn > ;
456
432
457
- async fn load_async < U > ( self , asc : & AsyncConn ) -> Result < Vec < U > , RunError < DieselError > >
433
+ async fn load_async < U > ( self , asc : & AsyncConn ) -> Result < Vec < U > , RunError >
458
434
where
459
435
U : Send + ' static ,
460
436
Self : LoadQuery < ' static , Conn , U > ;
461
437
462
- async fn get_result_async < U > ( self , asc : & AsyncConn ) -> Result < U , RunError < DieselError > >
438
+ async fn get_result_async < U > ( self , asc : & AsyncConn ) -> Result < U , RunError >
463
439
where
464
440
U : Send + ' static ,
465
441
Self : LoadQuery < ' static , Conn , U > ;
466
442
467
- async fn get_results_async < U > ( self , asc : & AsyncConn ) -> Result < Vec < U > , RunError < DieselError > >
443
+ async fn get_results_async < U > ( self , asc : & AsyncConn ) -> Result < Vec < U > , RunError >
468
444
where
469
445
U : Send + ' static ,
470
446
Self : LoadQuery < ' static , Conn , U > ;
471
447
472
- async fn first_async < U > ( self , asc : & AsyncConn ) -> Result < U , RunError < DieselError > >
448
+ async fn first_async < U > ( self , asc : & AsyncConn ) -> Result < U , RunError >
473
449
where
474
450
U : Send + ' static ,
475
451
Self : LimitDsl ,
@@ -483,38 +459,38 @@ where
483
459
Conn : ' static + DieselConnection ,
484
460
AsyncConn : Send + Sync + AsyncConnection < Conn > ,
485
461
{
486
- async fn execute_async ( self , asc : & AsyncConn ) -> Result < usize , RunError < DieselError > >
462
+ async fn execute_async ( self , asc : & AsyncConn ) -> Result < usize , RunError >
487
463
where
488
464
Self : ExecuteDsl < Conn > ,
489
465
{
490
466
asc. run ( |conn| self . execute ( conn) ) . await
491
467
}
492
468
493
- async fn load_async < U > ( self , asc : & AsyncConn ) -> Result < Vec < U > , RunError < DieselError > >
469
+ async fn load_async < U > ( self , asc : & AsyncConn ) -> Result < Vec < U > , RunError >
494
470
where
495
471
U : Send + ' static ,
496
472
Self : LoadQuery < ' static , Conn , U > ,
497
473
{
498
474
asc. run ( |conn| self . load ( conn) ) . await
499
475
}
500
476
501
- async fn get_result_async < U > ( self , asc : & AsyncConn ) -> Result < U , RunError < DieselError > >
477
+ async fn get_result_async < U > ( self , asc : & AsyncConn ) -> Result < U , RunError >
502
478
where
503
479
U : Send + ' static ,
504
480
Self : LoadQuery < ' static , Conn , U > ,
505
481
{
506
482
asc. run ( |conn| self . get_result ( conn) ) . await
507
483
}
508
484
509
- async fn get_results_async < U > ( self , asc : & AsyncConn ) -> Result < Vec < U > , RunError < DieselError > >
485
+ async fn get_results_async < U > ( self , asc : & AsyncConn ) -> Result < Vec < U > , RunError >
510
486
where
511
487
U : Send + ' static ,
512
488
Self : LoadQuery < ' static , Conn , U > ,
513
489
{
514
490
asc. run ( |conn| self . get_results ( conn) ) . await
515
491
}
516
492
517
- async fn first_async < U > ( self , asc : & AsyncConn ) -> Result < U , RunError < DieselError > >
493
+ async fn first_async < U > ( self , asc : & AsyncConn ) -> Result < U , RunError >
518
494
where
519
495
U : Send + ' static ,
520
496
Self : LimitDsl ,
@@ -529,10 +505,7 @@ pub trait AsyncSaveChangesDsl<Conn, AsyncConn>
529
505
where
530
506
Conn : ' static + DieselConnection ,
531
507
{
532
- async fn save_changes_async < Output > (
533
- self ,
534
- asc : & AsyncConn ,
535
- ) -> Result < Output , RunError < DieselError > >
508
+ async fn save_changes_async < Output > ( self , asc : & AsyncConn ) -> Result < Output , RunError >
536
509
where
537
510
Self : Sized ,
538
511
Conn : diesel:: query_dsl:: UpdateAndFetchResults < Self , Output > ,
@@ -546,10 +519,7 @@ where
546
519
Conn : ' static + DieselConnection ,
547
520
AsyncConn : Send + Sync + AsyncConnection < Conn > ,
548
521
{
549
- async fn save_changes_async < Output > (
550
- self ,
551
- asc : & AsyncConn ,
552
- ) -> Result < Output , RunError < DieselError > >
522
+ async fn save_changes_async < Output > ( self , asc : & AsyncConn ) -> Result < Output , RunError >
553
523
where
554
524
Conn : diesel:: query_dsl:: UpdateAndFetchResults < Self , Output > ,
555
525
Output : Send + ' static ,
0 commit comments