aboutsummaryrefslogtreecommitdiffstats
path: root/src/local
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/local/database.rs11
-rw-r--r--src/local/history.rs6
-rw-r--r--src/local/import.rs7
3 files changed, 9 insertions, 15 deletions
diff --git a/src/local/database.rs b/src/local/database.rs
index e2df9ba5..8e4b00ef 100644
--- a/src/local/database.rs
+++ b/src/local/database.rs
@@ -1,7 +1,7 @@
use chrono::Utc;
use std::path::Path;
-use eyre::{eyre, Result};
+use eyre::Result;
use rusqlite::{params, Connection};
use rusqlite::{Transaction, NO_PARAMS};
@@ -125,16 +125,11 @@ impl Database for Sqlite {
where id = ?1",
)?;
- let mut iter = stmt.query_map(params![id], |row| {
+ let history = stmt.query_row(params![id], |row| {
history_from_sqlite_row(Some(id.to_string()), row)
})?;
- let history = iter.next().unwrap();
-
- match history {
- Ok(i) => Ok(i),
- Err(e) => Err(eyre!("could not find item: {}", e)),
- }
+ Ok(history)
}
fn update(&self, h: &History) -> Result<()> {
diff --git a/src/local/history.rs b/src/local/history.rs
index 06a350fc..d88353f9 100644
--- a/src/local/history.rs
+++ b/src/local/history.rs
@@ -24,9 +24,9 @@ impl History {
session: Option<String>,
hostname: Option<String>,
) -> Self {
- let session = session.unwrap_or_else(|| {
- env::var("ATUIN_SESSION").unwrap_or_else(|_| Uuid::new_v4().to_simple().to_string())
- });
+ let session = session
+ .or_else(|| env::var("ATUIN_SESSION").ok())
+ .unwrap_or_else(|| Uuid::new_v4().to_simple().to_string());
let hostname =
hostname.unwrap_or_else(|| hostname::get().unwrap().to_str().unwrap().to_string());
diff --git a/src/local/import.rs b/src/local/import.rs
index 858e5786..ddccc75a 100644
--- a/src/local/import.rs
+++ b/src/local/import.rs
@@ -4,9 +4,9 @@
use std::io::{BufRead, BufReader, Seek, SeekFrom};
use std::{fs::File, path::Path};
-use eyre::{eyre, Result};
+use eyre::{Result, WrapErr};
-use crate::local::history::History;
+use super::history::History;
#[derive(Debug)]
pub struct Zsh {
@@ -72,8 +72,6 @@ impl Iterator for Zsh {
match self.file.read_line(&mut line) {
Ok(0) => None,
- Err(e) => Some(Err(eyre!("failed to parse line: {}", e))),
-
Ok(_) => {
let extended = line.starts_with(':');
@@ -91,6 +89,7 @@ impl Iterator for Zsh {
)))
}
}
+ Err(e) => Some(Err(e).wrap_err("failed to parse line")),
}
}
}