diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs index 407013f..8793b73 100644 --- a/atuin-client/src/settings.rs +++ b/atuin-client/src/settings.rs @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf}; use chrono::prelude::*; use chrono::Utc; use config::{Config, Environment, File as ConfigFile}; -use eyre::{eyre, Result}; +use eyre::{eyre, Context, Result}; use parse_duration::parse; pub const HISTORY_PAGE_SIZE: i64 = 100; @@ -105,8 +105,10 @@ impl Settings { let data_dir = atuin_common::utils::data_dir(); - create_dir_all(&config_dir)?; - create_dir_all(&data_dir)?; + create_dir_all(&config_dir) + .wrap_err_with(|| format!("could not create dir {:?}", config_dir))?; + create_dir_all(&data_dir) + .wrap_err_with(|| format!("could not create dir {:?}", data_dir))?; let mut config_file = if let Ok(p) = std::env::var("ATUIN_CONFIG_DIR") { PathBuf::from(p) @@ -134,14 +136,17 @@ impl Settings { s.set_default("search_mode", "prefix")?; if config_file.exists() { - s.merge(ConfigFile::with_name(config_file.to_str().unwrap()))?; + s.merge(ConfigFile::with_name(config_file.to_str().unwrap())) + .wrap_err_with(|| format!("could not load config file {:?}", config_file))?; } else { let example_config = include_bytes!("../config.toml"); - let mut file = File::create(config_file)?; - file.write_all(example_config)?; + let mut file = File::create(config_file).wrap_err("could not create config file")?; + file.write_all(example_config) + .wrap_err("could not write default config file")?; } - s.merge(Environment::with_prefix("atuin").separator("_"))?; + s.merge(Environment::with_prefix("atuin").separator("_")) + .wrap_err("could not load environment")?; // all paths should be expanded let db_path = s.get_str("db_path")?; diff --git a/src/command/mod.rs b/src/command/mod.rs index 6a79a32..0295036 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use eyre::Result; +use eyre::{Result, WrapErr}; use structopt::StructOpt; use atuin_client::database::Sqlite; @@ -96,8 +96,8 @@ pub enum AtuinCmd { impl AtuinCmd { pub async fn run(self) -> Result<()> { - let client_settings = ClientSettings::new()?; - let server_settings = ServerSettings::new()?; + let client_settings = ClientSettings::new().wrap_err("could not load client settings")?; + let server_settings = ServerSettings::new().wrap_err("could not load server settings")?; let db_path = PathBuf::from(client_settings.db_path.as_str()); @@ -151,8 +151,10 @@ impl AtuinCmd { register::run(&client_settings, &r.username, &r.email, &r.password) } Self::Key => { - let key = atuin_client::encryption::load_key(&client_settings)?; - println!("{}", atuin_client::encryption::encode_key(key)?); + use atuin_client::encryption::{encode_key, load_key}; + let key = load_key(&client_settings).wrap_err("could not load encryption key")?; + let encode = encode_key(key).wrap_err("could not encode encryption key")?; + println!("{}", encode); Ok(()) }