Skip to content

Commit cbdfee3

Browse files
authored
Merge pull request diesel-rs#3219 from Ten0/return_original_error_when_tm_broken_on_rollback
Return the original error when rollback attempt fails for `BrokenTransactionManager`
2 parents bc8d85d + 78fc741 commit cbdfee3

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

diesel/src/connection/transaction_manager.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ pub trait TransactionManager<Conn: Connection> {
5555
Self::commit_transaction(conn)?;
5656
Ok(value)
5757
}
58-
Err(user_error) => {
59-
Self::rollback_transaction(conn)?;
60-
Err(user_error)
61-
}
58+
Err(user_error) => match Self::rollback_transaction(conn) {
59+
Ok(()) => Err(user_error),
60+
Err(Error::BrokenTransactionManager) => {
61+
// In this case we are probably more interested by the
62+
// original error, which likely caused this
63+
Err(user_error)
64+
}
65+
Err(rollback_error) => Err(rollback_error.into()),
66+
},
6267
}
6368
}
6469
}

diesel/src/pg/transaction.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,15 @@ where
294294
Ok(value)
295295
}
296296
Err(user_error) => {
297-
AnsiTransactionManager::rollback_transaction(&mut *self.connection)?;
298-
Err(user_error)
297+
match AnsiTransactionManager::rollback_transaction(&mut *self.connection) {
298+
Ok(()) => Err(user_error),
299+
Err(Error::BrokenTransactionManager) => {
300+
// In this case we are probably more interested by the
301+
// original error, which likely caused this
302+
Err(user_error)
303+
}
304+
Err(rollback_error) => Err(rollback_error.into()),
305+
}
299306
}
300307
}
301308
}

0 commit comments

Comments
 (0)