Returns a generic error reason + reason description pair.
(error: &E)
| 752 | |
| 753 | /// Returns a generic error reason + reason description pair. |
| 754 | pub fn get_error_reason<E>(error: &E) -> (String, String) |
| 755 | where |
| 756 | E: ReasonCode + 'static, |
| 757 | { |
| 758 | let mut err_chain = eyre::Chain::new(error); |
| 759 | let reason_desc = if err_chain.len() > 1 { |
| 760 | format!( |
| 761 | "'{}' caused by: {}", |
| 762 | error, |
| 763 | err_chain.next_back().map_or("UNKNOWN".to_string(), |e| e.to_string()) |
| 764 | ) |
| 765 | } else { |
| 766 | error.to_string() |
| 767 | }; |
| 768 | |
| 769 | (error.reason_code(), reason_desc) |
| 770 | } |
| 771 | |
| 772 | #[cfg(test)] |
| 773 | mod test { |
no test coverage detected