From de7954483eb0ce6daeba6eb06e8ed91a7b0e1dfb Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 23 May 2020 23:02:28 -0400 Subject: include filenames in the error messages about file operations --- src/error.rs | 91 +++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 26 deletions(-) (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs index 418aa3a..3030079 100644 --- a/src/error.rs +++ b/src/error.rs @@ -9,8 +9,11 @@ pub enum Error { source: block_modes::InvalidKeyIvLength, }, - #[snafu(display("failed to create directory"))] - CreateDirectory { source: std::io::Error }, + #[snafu(display("failed to create directory at {}", file.display()))] + CreateDirectory { + source: std::io::Error, + file: std::path::PathBuf, + }, #[snafu(display("failed to decrypt"))] Decrypt { source: block_modes::BlockModeError }, @@ -51,23 +54,41 @@ pub enum Error { source: serde_path_to_error::Error, }, - #[snafu(display("failed to load config"))] - LoadConfig { source: std::io::Error }, + #[snafu(display("failed to load config from {}", file.display()))] + LoadConfig { + source: std::io::Error, + file: std::path::PathBuf, + }, - #[snafu(display("failed to load config"))] - LoadConfigAsync { source: tokio::io::Error }, + #[snafu(display("failed to load config from {}", file.display()))] + LoadConfigAsync { + source: tokio::io::Error, + file: std::path::PathBuf, + }, - #[snafu(display("failed to load config"))] - LoadConfigJson { source: serde_json::Error }, + #[snafu(display("failed to load config from {}", file.display()))] + LoadConfigJson { + source: serde_json::Error, + file: std::path::PathBuf, + }, - #[snafu(display("failed to load db"))] - LoadDb { source: std::io::Error }, + #[snafu(display("failed to load db from {}", file.display()))] + LoadDb { + source: std::io::Error, + file: std::path::PathBuf, + }, - #[snafu(display("failed to load db"))] - LoadDbAsync { source: tokio::io::Error }, + #[snafu(display("failed to load db from {}", file.display()))] + LoadDbAsync { + source: tokio::io::Error, + file: std::path::PathBuf, + }, - #[snafu(display("failed to load db"))] - LoadDbJson { source: serde_json::Error }, + #[snafu(display("failed to load db from {}", file.display()))] + LoadDbJson { + source: serde_json::Error, + file: std::path::PathBuf, + }, #[snafu(display("openssl error"))] OpenSSL { source: openssl::error::ErrorStack }, @@ -87,8 +108,11 @@ pub enum Error { #[snafu(display("error waiting for pinentry to exit"))] PinentryWait { source: tokio::io::Error }, - #[snafu(display("failed to remove db"))] - RemoveDb { source: std::io::Error }, + #[snafu(display("failed to remove db at {}", file.display()))] + RemoveDb { + source: std::io::Error, + file: std::path::PathBuf, + }, #[snafu(display("api request returned error: {}", status))] RequestFailed { status: u16 }, @@ -99,20 +123,35 @@ pub enum Error { #[snafu(display("error making api request"))] Reqwest { source: reqwest::Error }, - #[snafu(display("failed to save config"))] - SaveConfig { source: std::io::Error }, + #[snafu(display("failed to save config to {}", file.display()))] + SaveConfig { + source: std::io::Error, + file: std::path::PathBuf, + }, - #[snafu(display("failed to save config"))] - SaveConfigJson { source: serde_json::Error }, + #[snafu(display("failed to save config to {}", file.display()))] + SaveConfigJson { + source: serde_json::Error, + file: std::path::PathBuf, + }, - #[snafu(display("failed to save db"))] - SaveDb { source: std::io::Error }, + #[snafu(display("failed to save db to {}", file.display()))] + SaveDb { + source: std::io::Error, + file: std::path::PathBuf, + }, - #[snafu(display("failed to save db"))] - SaveDbAsync { source: tokio::io::Error }, + #[snafu(display("failed to save db to {}", file.display()))] + SaveDbAsync { + source: tokio::io::Error, + file: std::path::PathBuf, + }, - #[snafu(display("failed to save db"))] - SaveDbJson { source: serde_json::Error }, + #[snafu(display("failed to save db to {}", file.display()))] + SaveDbJson { + source: serde_json::Error, + file: std::path::PathBuf, + }, #[snafu(display("error spawning pinentry"))] Spawn { source: tokio::io::Error }, -- cgit v1.2.3-54-g00ecf