transaction: report failure to close transaction only in debug builds

When a transaction gets dropped without being committed or explicitly
discarded, we currently raise an assertion error. I added that check
because I kept forgetting to commit transactions. However, it's quite
normal to want to drop transactions in error cases. The current
assertion means that we panic and don't report the actual error to the
user in such cases. We should probably audit the code paths where we
commit transactions and decide for each if we simply want to to
discard the transaction or not. In some cases, we may want to commit
the transaction without integrating it in the operation log
(i.e. without creating a file entry in .jj/views/op_heads/). However,
we can do that later. For now, let's just make sure we don't panic
when dropping the transaction in release builds.
This commit is contained in:
Martin von Zweigbergk 2021-02-06 23:33:15 -08:00
parent 4ecbd89378
commit e0112a4be0

View file

@ -176,7 +176,7 @@ impl<'r> Transaction<'r> {
impl<'r> Drop for Transaction<'r> {
fn drop(&mut self) {
if !std::thread::panicking() {
assert!(self.closed, "Transaction was dropped without being closed.");
debug_assert!(self.closed, "Transaction was dropped without being closed.");
}
}
}