Skip to content

Commit

Permalink
Use DebugDropBomb
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Sep 2, 2024
1 parent 79e0155 commit 2f5ccf4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/result.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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."),
})),
}
}
Expand All @@ -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."),
})),
}
}
Expand Down Expand Up @@ -74,7 +74,7 @@ pub(crate) enum ErrorKind {
#[derive(Debug)]
pub(crate) struct CycleError {
cycle: Cycle,
bomb: DropBomb,
bomb: DebugDropBomb,
}

impl CycleError {
Expand All @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions tests/cycle_dropping_error_panics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn cycle_b(db: &dyn Db, input: MyInput) -> salsa::Result<String> {
}

#[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| {
Expand Down
18 changes: 2 additions & 16 deletions tests/parallel/parallel_cancellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
1 change: 1 addition & 0 deletions tests/parallel/parallel_cancellation_capture_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fn dummy(_db: &dyn KnobsDatabase, _input: MyInput) -> salsa::Result<String> {
// drops error -> panics

#[test]
#[cfg(debug_assertions)]
fn execute() {
let mut db = Knobs::default();

Expand Down

0 comments on commit 2f5ccf4

Please sign in to comment.