Skip to content

Commit 85c197e

Browse files
committed
Use turso assertion details parameter instead of interpolated strings
Convert panic!/assert! in turso-stress to turso_assert/turso_assert_unreachable with structured details blocks, so Antithesis gets proper metadata instead of baked-in format strings. Also remove redundant format!("{:?}", ...) wrappers in btree.rs and builder.rs details blocks since the macro already applies Debug formatting. https://claude.ai/code/session_012NRC1Tbyaoexyb8PruUQLG
1 parent 20b2314 commit 85c197e

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/storage/btree.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,7 @@ impl BTreeCursor {
23322332

23332333
if overflows {
23342334
*write_state = WriteState::Balancing;
2335-
turso_assert!(matches!(self.balance_state.sub_state, BalanceSubState::Start), "no balancing operation should be in progress during insert", { "state": format!("{:?}", self.state), "sub_state": format!("{:?}", self.balance_state.sub_state) });
2335+
turso_assert!(matches!(self.balance_state.sub_state, BalanceSubState::Start), "no balancing operation should be in progress during insert", { "state": self.state, "sub_state": self.balance_state.sub_state });
23362336
// If we balance, we must save the cursor position and seek to it later.
23372337
self.save_context(CursorContext::seek_eq_only(bkey));
23382338
} else {
@@ -2375,7 +2375,7 @@ impl BTreeCursor {
23752375
};
23762376
if overflows || underflows {
23772377
*write_state = WriteState::Balancing;
2378-
turso_assert!(matches!(self.balance_state.sub_state, BalanceSubState::Start), "no balancing operation should be in progress during overwrite", { "state": format!("{:?}", self.state), "sub_state": format!("{:?}", self.balance_state.sub_state) });
2378+
turso_assert!(matches!(self.balance_state.sub_state, BalanceSubState::Start), "no balancing operation should be in progress during overwrite", { "state": self.state, "sub_state": self.balance_state.sub_state });
23792379
// If we balance, we must save the cursor position and seek to it later.
23802380
self.save_context(CursorContext::seek_eq_only(bkey));
23812381
} else {
@@ -5419,7 +5419,7 @@ impl CursorTrait for BTreeCursor {
54195419
}
54205420
}
54215421
let balance_both = leaf_underflows && interior_overflows_or_underflows;
5422-
turso_assert!(matches!(self.balance_state.sub_state, BalanceSubState::Start), "no balancing operation should be in progress during delete", { "sub_state": format!("{:?}", self.balance_state.sub_state) });
5422+
turso_assert!(matches!(self.balance_state.sub_state, BalanceSubState::Start), "no balancing operation should be in progress during delete", { "sub_state": self.balance_state.sub_state });
54235423
let post_balancing_seek_key = post_balancing_seek_key
54245424
.take()
54255425
.expect("post_balancing_seek_key should be Some");

core/vdbe/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ impl ProgramBuilder {
925925
/// reordering the emitted instructions.
926926
#[inline]
927927
pub fn preassign_label_to_next_insn(&mut self, label: BranchOffset) {
928-
turso_assert!(label.is_label(), "BranchOffset should be a label", { "label": format!("{:?}", label) });
928+
turso_assert!(label.is_label(), "BranchOffset should be a label", { "label": label });
929929
self._resolve_label(label, self.offset().sub(1u32), JumpTarget::AfterThisInsn);
930930
}
931931

testing/stress/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ tokio = { workspace = true, features = ["full"] }
3333
tracing-appender = { workspace = true }
3434
tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
3535
turso = { workspace = true }
36+
turso_macros = { workspace = true }
3637
rusqlite = { workspace = true }
3738

3839
[target.'cfg(antithesis)'.dependencies]
3940
antithesis_sdk = { workspace = true, features = ["full"] }
41+
serde_json = { workspace = true }
4042

4143
[target.'cfg(shuttle)'.dependencies]
4244
shuttle = { workspace = true }

testing/stress/main.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ pub fn spawn_log_level_watcher(reload_handle: LogLevelReloadHandle) {
556556
fn sqlite_integrity_check(
557557
db_path: &std::path::Path,
558558
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
559-
assert!(db_path.exists());
559+
turso_macros::turso_assert!(db_path.exists(), "database path must exist", { "path": db_path });
560560
let conn = rusqlite::Connection::open(db_path)?;
561561
let mut stmt = conn.prepare_cached("SELECT * FROM pragma_integrity_check;")?;
562562
let mut rows = stmt.query(())?;
@@ -565,7 +565,10 @@ fn sqlite_integrity_check(
565565
while let Some(row) = rows.next()? {
566566
result.push(row.get(0)?);
567567
}
568-
assert!(!result.is_empty());
568+
turso_macros::turso_assert!(
569+
!result.is_empty(),
570+
"integrity check result must not be empty"
571+
);
569572
if !result[0].eq_ignore_ascii_case("ok") {
570573
// Build a list of problems
571574
result.iter_mut().for_each(|row| *row = format!("- {row}"));
@@ -759,7 +762,7 @@ async fn async_main(opts: Opts) -> Result<(), Box<dyn std::error::Error + Send +
759762
}
760763
Err(e) => {
761764
log_sql(&sql_log, thread, stmt, &format!("ERROR(fatal): {e}"));
762-
panic!("Error creating table: {e}");
765+
turso_macros::turso_assert_unreachable!("fatal error creating table", { "thread": thread, "stmt": stmt, "error": e });
763766
}
764767
}
765768
}
@@ -840,7 +843,7 @@ async fn async_main(opts: Opts) -> Result<(), Box<dyn std::error::Error + Send +
840843
Err(e) => match e {
841844
turso::Error::Corrupt(e) => {
842845
log_sql(&sql_log, thread, &sql, &format!("ERROR(corrupt): {e}"));
843-
panic!("thread#{thread} Error[FATAL] executing query: {e}");
846+
turso_macros::turso_assert_unreachable!("corrupt error executing query", { "thread": thread, "error": e, "sql": sql });
844847
}
845848
turso::Error::Constraint(e) => {
846849
log_sql(&sql_log, thread, &sql, &format!("ERROR(constraint): {e}"));
@@ -876,7 +879,7 @@ async fn async_main(opts: Opts) -> Result<(), Box<dyn std::error::Error + Send +
876879
}
877880
_ => {
878881
log_sql(&sql_log, thread, &sql, &format!("ERROR(fatal): {e}"));
879-
panic!("thread#{thread} Error[FATAL] executing query: {e}");
882+
turso_macros::turso_assert_unreachable!("fatal error executing query", { "thread": thread, "error": e, "sql": sql });
880883
}
881884
},
882885
}
@@ -906,13 +909,13 @@ async fn async_main(opts: Opts) -> Result<(), Box<dyn std::error::Error + Send +
906909
"PRAGMA integrity_check",
907910
&format!("ERROR: {value:?}"),
908911
);
909-
panic!("thread#{thread} integrity check failed: {value:?}");
912+
turso_macros::turso_assert_unreachable!("integrity check failed", { "thread": thread, "value": value });
910913
}
911914
log_sql(&sql_log, thread, "PRAGMA integrity_check", "OK");
912915
}
913916
Ok(None) => {
914917
log_sql(&sql_log, thread, "PRAGMA integrity_check", "ERROR: no rows");
915-
panic!("thread#{thread} integrity check failed: no rows");
918+
turso_macros::turso_assert_unreachable!("integrity check returned no rows", { "thread": thread });
916919
}
917920
Err(e) => {
918921
log_sql(
@@ -926,7 +929,7 @@ async fn async_main(opts: Opts) -> Result<(), Box<dyn std::error::Error + Send +
926929
}
927930
match res.next().await {
928931
Ok(Some(_)) => {
929-
panic!("thread#{thread} integrity check failed: more than 1 row")
932+
turso_macros::turso_assert_unreachable!("integrity check returned more than 1 row", { "thread": thread });
930933
}
931934
Err(e) => println!("thread#{thread} Error performing integrity check: {e}"),
932935
_ => {}

0 commit comments

Comments
 (0)