From e0112a4be0176c9e8ca71aea3158787d9ecbc80f Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 6 Feb 2021 23:33:15 -0800 Subject: [PATCH] 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. --- lib/src/transaction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/transaction.rs b/lib/src/transaction.rs index 4980c8de9..3bf636988 100644 --- a/lib/src/transaction.rs +++ b/lib/src/transaction.rs @@ -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."); } } }