Skip to content

Commit d093464

Browse files
committed
improve QueryBuilder error message
1 parent d6c91ee commit d093464

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

sqlx-core/src/query_builder.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ impl<'args, DB: Database> Default for QueryBuilder<'args, DB> {
4343
}
4444
}
4545

46+
const ERROR: &str = "BUG: query must not be shared at this point in time";
47+
4648
impl<'args, DB: Database> QueryBuilder<'args, DB>
4749
where
4850
DB: Database,
@@ -118,7 +120,7 @@ where
118120
/// e.g. check that strings aren't too long, numbers are within expected ranges, etc.
119121
pub fn push(&mut self, sql: impl Display) -> &mut Self {
120122
self.sanity_check();
121-
let query: &mut String = Arc::get_mut(&mut self.query).expect("");
123+
let query: &mut String = Arc::get_mut(&mut self.query).expect(ERROR);
122124

123125
write!(query, "{sql}").expect("error formatting `sql`");
124126

@@ -161,7 +163,7 @@ where
161163
.expect("BUG: Arguments taken already");
162164
arguments.add(value).expect("Failed to add argument");
163165

164-
let query: &mut String = Arc::get_mut(&mut self.query).expect("");
166+
let query: &mut String = Arc::get_mut(&mut self.query).expect(ERROR);
165167
arguments
166168
.format_placeholder(query)
167169
.expect("error in format_placeholder");
@@ -516,7 +518,7 @@ where
516518
/// The query is truncated to the initial fragment provided to [`new()`][Self::new] and
517519
/// the bind arguments are reset.
518520
pub fn reset(&mut self) -> &mut Self {
519-
let query: &mut String = Arc::get_mut(&mut self.query).expect("");
521+
let query: &mut String = Arc::get_mut(&mut self.query).expect(ERROR);
520522
query.truncate(self.init_len);
521523
self.arguments = Some(Default::default());
522524

0 commit comments

Comments
 (0)