From 0736dd67d690c597e93324e19126f6c48b81f7c4 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 22 Oct 2018 19:33:14 +0200 Subject: decode_datetime(): Return a `Result` Make a custom error type because it's trickier to integrate with 'error-chain' given that 'magic-crypt''s `Error` type doesn't implement the `std::error::Error` trait. For the same reason, we can't use that as the `cause` for `DateCryptError::Decrypt`. This allows us to capture the errors without panicking. Include some additional cleanups as a result of removing the `use std::result` and `use errors::*` imports. --- src/errors.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/errors.rs') diff --git a/src/errors.rs b/src/errors.rs index 5f09c27..c2048e9 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,3 +1,5 @@ +use chrono; +use magic_crypt; use xdg; error_chain! { @@ -15,3 +17,18 @@ quick_error! { } } } + +quick_error! { + #[derive(Debug)] + pub enum DateCryptError { + DateParse(err: chrono::format::ParseError) { + from() + cause(err) + display("unable to parse timestamp") + } + Decrypt(err: magic_crypt::Error) { + from() + display("unable to read trial key") + } + } +} -- cgit v1.2.3