|
| 1 | +use std::sync::PoisonError; |
| 2 | + |
1 | 3 | /// PostgreSQL archive result type
|
2 | 4 | pub type Result<T, E = Error> = core::result::Result<T, E>;
|
3 | 5 |
|
@@ -111,6 +113,29 @@ impl From<url::ParseError> for Error {
|
111 | 113 | }
|
112 | 114 | }
|
113 | 115 |
|
| 116 | +#[cfg(feature = "maven")] |
| 117 | +/// Converts a [`quick_xml::DeError`] into a [`ParseError`](Error::ParseError) |
| 118 | +impl From<quick_xml::DeError> for Error { |
| 119 | + fn from(error: quick_xml::DeError) -> Self { |
| 120 | + Error::ParseError(error.to_string()) |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +#[cfg(feature = "zip")] |
| 125 | +/// Converts a [`zip::result::ZipError`] into a [`ParseError`](Error::Unexpected) |
| 126 | +impl From<zip::result::ZipError> for Error { |
| 127 | + fn from(error: zip::result::ZipError) -> Self { |
| 128 | + Error::Unexpected(error.to_string()) |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +/// Converts a [`std::sync::PoisonError<T>`] into a [`ParseError`](Error::PoisonedLock) |
| 133 | +impl<T> From<PoisonError<T>> for Error { |
| 134 | + fn from(value: PoisonError<T>) -> Self { |
| 135 | + Error::PoisonedLock(value.to_string()) |
| 136 | + } |
| 137 | +} |
| 138 | + |
114 | 139 | /// These are relatively low value tests; they are here to reduce the coverage gap and
|
115 | 140 | /// ensure that the error conversions are working as expected.
|
116 | 141 | #[cfg(test)]
|
@@ -199,4 +224,33 @@ mod test {
|
199 | 224 | let error = Error::from(parse_error);
|
200 | 225 | assert_eq!(error.to_string(), "empty host");
|
201 | 226 | }
|
| 227 | + |
| 228 | + #[cfg(feature = "maven")] |
| 229 | + #[test] |
| 230 | + fn test_from_quick_xml_error() { |
| 231 | + let xml = "<invalid>"; |
| 232 | + let quick_xml_error = quick_xml::de::from_str::<String>(xml).expect_err("quick_xml error"); |
| 233 | + let error = Error::from(quick_xml_error); |
| 234 | + assert!(matches!(error, Error::ParseError(_))); |
| 235 | + } |
| 236 | + |
| 237 | + #[cfg(feature = "zip")] |
| 238 | + #[test] |
| 239 | + fn test_from_zip_error() { |
| 240 | + let zip_error = zip::result::ZipError::FileNotFound; |
| 241 | + let error = Error::from(zip_error); |
| 242 | + assert!(matches!(error, Error::Unexpected(_))); |
| 243 | + assert!( |
| 244 | + error |
| 245 | + .to_string() |
| 246 | + .contains("specified file not found in archive") |
| 247 | + ); |
| 248 | + } |
| 249 | + |
| 250 | + #[test] |
| 251 | + fn test_from_poisoned_lock() { |
| 252 | + let error = Error::from(std::sync::PoisonError::new(())); |
| 253 | + assert!(matches!(error, Error::PoisonedLock(_))); |
| 254 | + assert!(error.to_string().contains("poisoned lock")); |
| 255 | + } |
202 | 256 | }
|
0 commit comments