summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConrad Ludgate <conradludgate@gmail.com>2021-11-17 11:50:34 +0000
committerGitHub <noreply@github.com>2021-11-17 11:50:34 +0000
commitf539f60ae420f9ac8ae6dd4a82b13c505bc9005a (patch)
treef18fc332ea2be2fd48fed8969a31a855402f6f43
parent2e59d6a588661f527edb6ca49f14fc2dab1e436a (diff)
chore: add more eyre contexts (#200)
* chore: add more eyre contexts * chore: rustfmt
-rw-r--r--atuin-client/src/settings.rs19
-rw-r--r--src/command/mod.rs12
2 files changed, 19 insertions, 12 deletions
diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs
index 407013f0..8793b73e 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 6a79a32f..02950365 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(())
}