diff --git a/src/result.rs b/src/result.rs index 89210b7b..74cfb43a 100644 --- a/src/result.rs +++ b/src/result.rs @@ -1,5 +1,5 @@ use crate::{with_attached_database, Cycle}; -use drop_bomb::DropBomb; +use drop_bomb::DebugDropBomb; use std::fmt; use std::fmt::Debug; @@ -22,7 +22,7 @@ impl Error { Error { kind: Box::new(ErrorKind::Cancelled(CancelledError { reason, - bomb: DropBomb::new("Cancellation errors must be propagated inside salsa queries. If you see this message outside a salsa query, please open an issue."), + bomb: DebugDropBomb::new("Cancellation errors must be propagated inside salsa queries. If you see this message outside a salsa query, please open an issue."), })), } } @@ -31,7 +31,7 @@ impl Error { Self { kind: Box::new(ErrorKind::Cycle(CycleError { cycle, - bomb: DropBomb::new("Cycle errors must be propagated so that Salsa can resolve the cycle. If you see this message outside a salsa query, please open an issue."), + bomb: DebugDropBomb::new("Cycle errors must be propagated so that Salsa can resolve the cycle. If you see this message outside a salsa query, please open an issue."), })), } } @@ -74,7 +74,7 @@ pub(crate) enum ErrorKind { #[derive(Debug)] pub(crate) struct CycleError { cycle: Cycle, - bomb: DropBomb, + bomb: DebugDropBomb, } impl CycleError { @@ -87,12 +87,12 @@ impl CycleError { #[derive(Debug)] pub(crate) struct CancelledError { reason: Cancelled, - bomb: DropBomb, + bomb: DebugDropBomb, } impl Drop for CancelledError { fn drop(&mut self) { - if with_attached_database(|_| {}).is_none() { + if !self.bomb.is_defused() && with_attached_database(|_| {}).is_none() { // We are outside a query. It's okay if the user drops the error now self.bomb.defuse(); } diff --git a/tests/cycle_dropping_error_panics.rs b/tests/cycle_dropping_error_panics.rs index 90c784f4..8338443f 100644 --- a/tests/cycle_dropping_error_panics.rs +++ b/tests/cycle_dropping_error_panics.rs @@ -31,6 +31,7 @@ fn cycle_b(db: &dyn Db, input: MyInput) -> salsa::Result { } #[test] +#[cfg(debug_assertions)] #[should_panic(expected = "Cycle errors must be propagated so that Salsa can resolve the cycle.")] fn execute() { salsa::DatabaseImpl::new().attach(|db| { diff --git a/tests/parallel/parallel_cancellation.rs b/tests/parallel/parallel_cancellation.rs index d07fa63a..3d015b27 100644 --- a/tests/parallel/parallel_cancellation.rs +++ b/tests/parallel/parallel_cancellation.rs @@ -61,20 +61,6 @@ fn execute() { let cancelled = thread_a.join().unwrap().unwrap_err(); // and inspect the output - expect_test::expect![[r#" - Error { - kind: Cancelled( - CancelledError { - reason: PendingWrite, - bomb: DropBomb( - RealBomb { - msg: "Cancellation errors must be propagated inside salsa queries. If you see this message outside a salsa query, please open an issue.", - defused: false, - }, - ), - }, - ), - } - "#]] - .assert_debug_eq(&cancelled); + expect_test::expect![[r#"cancelled because of pending write"#]] + .assert_eq(&cancelled.to_string()); } diff --git a/tests/parallel/parallel_cancellation_capture_error.rs b/tests/parallel/parallel_cancellation_capture_error.rs index 011e419c..286a89bc 100644 --- a/tests/parallel/parallel_cancellation_capture_error.rs +++ b/tests/parallel/parallel_cancellation_capture_error.rs @@ -47,6 +47,7 @@ fn dummy(_db: &dyn KnobsDatabase, _input: MyInput) -> salsa::Result { // drops error -> panics #[test] +#[cfg(debug_assertions)] fn execute() { let mut db = Knobs::default();