Skip to content

impl PartialEq for HandlerError #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion lambda-runtime/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The error module defines the error types that can be returned
//! by custom handlers as well as the runtime itself.
use std::{env, error::Error, fmt};
use std::{cmp, env, error::Error, fmt};

use backtrace;
use lambda_runtime_client::error;
Expand Down Expand Up @@ -118,12 +118,21 @@ impl From<error::ApiError> for RuntimeError {
/// The error type for functions that are used as the `Handler` type. New errors
/// should be instantiated using the `new_error()` method of the `runtime::Context`
/// object passed to the handler function.
///
/// An implementation of `PartialEq` is provided and based it's comparison on the `msg`
/// field.
#[derive(Debug, Clone)]
pub struct HandlerError {
msg: String,
backtrace: Option<backtrace::Backtrace>,
}

impl cmp::PartialEq for HandlerError {
fn eq(&self, other: &HandlerError) -> bool {
self.msg == other.msg
}
}

impl fmt::Display for HandlerError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.msg)
Expand Down Expand Up @@ -169,3 +178,22 @@ impl error::RuntimeApiError for HandlerError {
}
}
}

#[cfg(test)]
mod tests {
use super::HandlerError;

#[test]
fn handler_error_impls_partialeq() {
assert_eq!(
HandlerError {
msg: "test".into(),
backtrace: Default::default()
},
HandlerError {
msg: "test".into(),
backtrace: Some(Default::default())
}
)
}
}