sqlx-error 0.6.0

A wrapper around `sqlx::Error` to provide error path and additional context
docs.rs failed to build sqlx-error-0.6.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: sqlx-error-0.5.1

License Crates.io Docs.rs

sqlx-error

A wrapper around sqlx::Error to provide error path and additional context.

Usage

use sqlx_error::{sqlx_error, SqlxError};

#[derive(Debug, thiserror::Error)]
pub enum MyError {
    #[error(transparent)]
    Sqlx(#[from] SqlxError),
}

/// If you have a single sqlx query per function, the function path by itself could provide
/// enough context
fn foo() -> Result<(), MyError> {
    Err(sqlx::Error::RowNotFound).map_err(sqlx_error!())?;
    Ok(())
}

/// Or you can add more context
fn bar() -> Result<(), MyError> {
    Err(sqlx::Error::RowNotFound).map_err(sqlx_error!("more context"))?;
    Ok(())
}

fn main() {
    assert_eq!(
        foo().unwrap_err().to_string(),
        "sqlx: rust_out::foo at src/lib.rs:15"
    );
    assert_eq!(
        bar().unwrap_err().to_string(),
        "sqlx: more context in rust_out::bar at src/lib.rs:21"
    );
}

Contributing

Please run .pre-commit.sh before sending a PR, it will check everything.

This project is licensed under the MIT license.