pub struct Error { /* private fields */ }Expand description
Error type returned across all Sift crates.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new<E>(kind: ErrorKind, err: E) -> Self
pub fn new<E>(kind: ErrorKind, err: E) -> Self
Initializes an Error from a standard error type.
This constructor wraps a standard library error (or any type implementing
std::error::Error) into a Sift error with the specified ErrorKind.
§Arguments
kind- The category of error that occurrederr- The underlying error to wrap
§Example
use sift_error::{Error, ErrorKind};
use std::io;
let io_error = io::Error::new(io::ErrorKind::NotFound, "file not found");
let sift_error = Error::new(ErrorKind::IoError, io_error);Sourcepub fn new_msg<S: AsRef<str>>(kind: ErrorKind, msg: S) -> Self
pub fn new_msg<S: AsRef<str>>(kind: ErrorKind, msg: S) -> Self
Initializes an Error with a generic message string.
This constructor creates an error from a string message without wrapping an underlying error type.
§Arguments
kind- The category of error that occurredmsg- A string message describing the error
§Example
use sift_error::{Error, ErrorKind};
let error = Error::new_msg(ErrorKind::NotFoundError, "resource not found");Sourcepub fn new_general<S: AsRef<str>>(msg: S) -> Self
pub fn new_general<S: AsRef<str>>(msg: S) -> Self
Initializes a general catch-all type of Error.
Contributors should be careful not to use this unless strictly necessary. Prefer more specific ErrorKind variants when possible.
§Arguments
msg- A string message describing the error
§Example
use sift_error::Error;
let error = Error::new_general("unexpected condition occurred");Sourcepub fn new_arg_error<S: AsRef<str>>(msg: S) -> Self
pub fn new_arg_error<S: AsRef<str>>(msg: S) -> Self
Used for user-errors that have to do with bad arguments.
This is a convenience constructor for argument validation errors.
§Arguments
msg- A string message describing the argument validation failure
§Example
use sift_error::Error;
fn validate_age(age: i32) -> Result<(), Error> {
if age < 0 {
return Err(Error::new_arg_error("age must be non-negative"));
}
Ok(())
}Sourcepub fn new_empty_response<S: AsRef<str>>(msg: S) -> Self
pub fn new_empty_response<S: AsRef<str>>(msg: S) -> Self
Creates an error for empty gRPC responses.
Tonic response types usually return optional types that we need to handle; if responses are empty then this is the appropriate way to initialize an Error for that situation, though this has never been observed in practice.
§Arguments
msg- A string message describing the empty response situation
§Example
use sift_error::Error;
// This would typically be used when a gRPC response is unexpectedly empty
let error = Error::new_empty_response("asset response was empty");