Skip to main content

capture_error_with_sql

Function capture_error_with_sql 

Source
pub fn capture_error_with_sql<E: Error>(
    err: &E,
    statement: &str,
    context: HashMap<String, Value>,
    user: Option<HashMap<String, Value>>,
)
Expand description

The same as capture_error, for an error caused by a database call: pass the SQL that ran. A Rust error carries no statement of its own and no Rust database crate puts one on its error types, so the code that ran the query has to hand it over.

With Configuration::capture_sql_objects on (the default), the names of the stored procedure, table and view the statement touched are sent, so an issue says where to start looking. With Configuration::capture_sql_statement on too (off by default), the statement itself is sent as well, with every string and number replaced by ? first. The raw statement never leaves this process either way.

ⓘ
if let Err(err) = sqlx::query(QUERY).bind(id).execute(&pool).await {
    forge_ops_tracker::capture_error_with_sql(&err, QUERY, HashMap::new(), None);
}