|
1 | 1 | //! The error module defines the error types that can be returned |
2 | 2 | //! by custom handlers as well as the runtime itself. |
3 | | -use std::{env, error::Error, fmt}; |
| 3 | +use std::{cmp, env, error::Error, fmt}; |
4 | 4 |
|
5 | 5 | use backtrace; |
6 | 6 | use lambda_runtime_client::error; |
@@ -118,12 +118,21 @@ impl From<error::ApiError> for RuntimeError { |
118 | 118 | /// The error type for functions that are used as the `Handler` type. New errors |
119 | 119 | /// should be instantiated using the `new_error()` method of the `runtime::Context` |
120 | 120 | /// object passed to the handler function. |
| 121 | +/// |
| 122 | +/// An implementation of `PartialEq` is provided and based it's comparison on the `msg` |
| 123 | +/// field. |
121 | 124 | #[derive(Debug, Clone)] |
122 | 125 | pub struct HandlerError { |
123 | 126 | msg: String, |
124 | 127 | backtrace: Option<backtrace::Backtrace>, |
125 | 128 | } |
126 | 129 |
|
| 130 | +impl cmp::PartialEq for HandlerError { |
| 131 | + fn eq(&self, other: &HandlerError) -> bool { |
| 132 | + self.msg == other.msg |
| 133 | + } |
| 134 | +} |
| 135 | + |
127 | 136 | impl fmt::Display for HandlerError { |
128 | 137 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
129 | 138 | write!(f, "{}", self.msg) |
@@ -169,3 +178,22 @@ impl error::RuntimeApiError for HandlerError { |
169 | 178 | } |
170 | 179 | } |
171 | 180 | } |
| 181 | + |
| 182 | +#[cfg(test)] |
| 183 | +mod tests { |
| 184 | + use super::HandlerError; |
| 185 | + |
| 186 | + #[test] |
| 187 | + fn handler_error_impls_partialeq() { |
| 188 | + assert_eq!( |
| 189 | + HandlerError { |
| 190 | + msg: "test".into(), |
| 191 | + backtrace: Default::default() |
| 192 | + }, |
| 193 | + HandlerError { |
| 194 | + msg: "test".into(), |
| 195 | + backtrace: Some(Default::default()) |
| 196 | + } |
| 197 | + ) |
| 198 | + } |
| 199 | +} |
0 commit comments