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 more