pub struct Diagnostic {
pub error_type: String,
pub error_message: String,
}Expand description
Diagnostic information about an error.
Diagnostic is automatically derived for some common types,
like boxed types that implement Error.
If you use an error type which comes from a external crate like anyhow,
you need convert it to common types like Box<dyn std::error::Error>.
See the examples for more details.
error_type is derived from the type name of
the original error with std::any::type_name as a fallback, which may
not be reliable for conditional error handling.
To get more descriptive error_type fields, you can implement From for your error type.
That gives you full control on what the error_type is.
Example:
use lambda_runtime::{Diagnostic, Error, LambdaEvent};
#[derive(Debug)]
struct ErrorResponse(&'static str);
impl From<ErrorResponse> for Diagnostic {
fn from(error: ErrorResponse) -> Diagnostic {
Diagnostic {
error_type: "MyError".into(),
error_message: error.0.to_string(),
}
}
}
async fn function_handler(_event: LambdaEvent<()>) -> Result<(), ErrorResponse> {
Err(ErrorResponse("this is an error response"))
}Fields§
§error_type: Stringerror_type is the type of exception or error returned by the function.
Use this field to categorize the different kinds of errors that your function
might experience.
In standard implementations, error_type is derived from the type name of the original error with
std::any::type_name, however this is not descriptive enough for an error type.
Implement your own Into<Diagnostic> to return a more descriptive error type.
error_message: Stringerror_message is a string expression of the error.
In standard implementations, it’s the output from the Display
implementation of the original error.
Trait Implementations§
Source§impl Clone for Diagnostic
impl Clone for Diagnostic
Source§fn clone(&self) -> Diagnostic
fn clone(&self) -> Diagnostic
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Diagnostic
impl Debug for Diagnostic
Source§impl<'de> Deserialize<'de> for Diagnostic
impl<'de> Deserialize<'de> for Diagnostic
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&'static str> for Diagnostic
impl From<&'static str> for Diagnostic
Source§impl From<Error> for Diagnostic
impl From<Error> for Diagnostic
Source§impl From<Error> for Diagnostic
Available on crate feature anyhow only.
impl From<Error> for Diagnostic
anyhow only.Source§fn from(value: Error) -> Diagnostic
fn from(value: Error) -> Diagnostic
Source§impl From<Infallible> for Diagnostic
impl From<Infallible> for Diagnostic
Source§fn from(value: Infallible) -> Self
fn from(value: Infallible) -> Self
Source§impl From<Report> for Diagnostic
Available on crate feature eyre only.
impl From<Report> for Diagnostic
eyre only.Source§fn from(value: Report) -> Diagnostic
fn from(value: Report) -> Diagnostic
Source§impl From<Report> for Diagnostic
Available on crate feature miette only.
impl From<Report> for Diagnostic
miette only.