Skip to content

Commit

Permalink
impl PartialEq for HandlerError (awslabs#43)
Browse files Browse the repository at this point in the history
* impl PartialEq for HandleError

* document partialeq
  • Loading branch information
softprops authored and davidbarsky committed Dec 11, 2018
1 parent 090d0f0 commit 3b7ce41
Showing 1 changed file with 29 additions and 1 deletion.
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())
}
)
}
}

0 comments on commit 3b7ce41

Please sign in to comment.