aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-client
diff options
context:
space:
mode:
authorConrad Ludgate <conradludgate@gmail.com>2023-09-26 14:52:45 +0100
committerGitHub <noreply@github.com>2023-09-26 14:52:45 +0100
commitfc1a48a4f204dfe77bd8d4f82cfb3e64ade9d028 (patch)
tree72239a49993bfb023c8979c5ff4821ca3878b708 /atuin-client
parentbetter sync error messages (#1254) (diff)
downloadatuin-fc1a48a4f204dfe77bd8d4f82cfb3e64ade9d028.zip
handle missing entries (fixes #1236) (#1253)
* fix #1236 * lints
Diffstat (limited to 'atuin-client')
-rw-r--r--atuin-client/src/database.rs23
-rw-r--r--atuin-client/src/history.rs14
-rw-r--r--atuin-client/src/secrets.rs2
-rw-r--r--atuin-client/src/sync.rs2
4 files changed, 17 insertions, 24 deletions
diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs
index 16a4a43f..1a3dea16 100644
--- a/atuin-client/src/database.rs
+++ b/atuin-client/src/database.rs
@@ -73,7 +73,7 @@ pub trait Database: Send + Sync + 'static {
async fn save(&mut self, h: &History) -> Result<()>;
async fn save_bulk(&mut self, h: &[History]) -> Result<()>;
- async fn load(&self, id: &str) -> Result<History>;
+ async fn load(&self, id: &str) -> Result<Option<History>>;
async fn list(
&self,
filter: FilterMode,
@@ -86,8 +86,7 @@ pub trait Database: Send + Sync + 'static {
async fn update(&self, h: &History) -> Result<()>;
async fn history_count(&self) -> Result<i64>;
- async fn first(&self) -> Result<History>;
- async fn last(&self) -> Result<History>;
+ async fn last(&self) -> Result<Option<History>>;
async fn before(&self, timestamp: OffsetDateTime, count: i64) -> Result<Vec<History>>;
async fn delete(&self, mut h: History) -> Result<()>;
@@ -216,13 +215,13 @@ impl Database for Sqlite {
Ok(())
}
- async fn load(&self, id: &str) -> Result<History> {
+ async fn load(&self, id: &str) -> Result<Option<History>> {
debug!("loading history item {}", id);
let res = sqlx::query("select * from history where id = ?1")
.bind(id)
.map(Self::query_history)
- .fetch_one(&self.pool)
+ .fetch_optional(&self.pool)
.await?;
Ok(res)
@@ -308,22 +307,12 @@ impl Database for Sqlite {
Ok(res)
}
- async fn first(&self) -> Result<History> {
- let res =
- sqlx::query("select * from history where duration >= 0 order by timestamp asc limit 1")
- .map(Self::query_history)
- .fetch_one(&self.pool)
- .await?;
-
- Ok(res)
- }
-
- async fn last(&self) -> Result<History> {
+ async fn last(&self) -> Result<Option<History>> {
let res = sqlx::query(
"select * from history where duration >= 0 order by timestamp desc limit 1",
)
.map(Self::query_history)
- .fetch_one(&self.pool)
+ .fetch_optional(&self.pool)
.await?;
Ok(res)
diff --git a/atuin-client/src/history.rs b/atuin-client/src/history.rs
index f4c0a8eb..fbcb169c 100644
--- a/atuin-client/src/history.rs
+++ b/atuin-client/src/history.rs
@@ -210,9 +210,11 @@ mod tests {
// Test that we don't save history where necessary
#[test]
fn privacy_test() {
- let mut settings = Settings::default();
- settings.cwd_filter = RegexSet::new(["^/supasecret"]).unwrap();
- settings.history_filter = RegexSet::new(["^psql"]).unwrap();
+ let settings = Settings {
+ cwd_filter: RegexSet::new(["^/supasecret"]).unwrap(),
+ history_filter: RegexSet::new(["^psql"]).unwrap(),
+ ..Settings::default()
+ };
let normal_command: History = History::capture()
.timestamp(time::OffsetDateTime::now_utc())
@@ -258,8 +260,10 @@ mod tests {
#[test]
fn disable_secrets() {
- let mut settings = Settings::default();
- settings.secrets_filter = false;
+ let settings = Settings {
+ secrets_filter: false,
+ ..Settings::default()
+ };
let stripe_key: History = History::capture()
.timestamp(time::OffsetDateTime::now_utc())
diff --git a/atuin-client/src/secrets.rs b/atuin-client/src/secrets.rs
index ba6aee66..0f751a8a 100644
--- a/atuin-client/src/secrets.rs
+++ b/atuin-client/src/secrets.rs
@@ -46,7 +46,7 @@ mod tests {
fn test_secrets() {
for (name, regex, test) in SECRET_PATTERNS {
let re =
- Regex::new(regex).expect(format!("Failed to compile regex for {name}").as_str());
+ Regex::new(regex).unwrap_or_else(|_| panic!("Failed to compile regex for {name}"));
assert!(re.is_match(test), "{name} test failed!");
}
diff --git a/atuin-client/src/sync.rs b/atuin-client/src/sync.rs
index bd2ff474..ebfb47c1 100644
--- a/atuin-client/src/sync.rs
+++ b/atuin-client/src/sync.rs
@@ -109,7 +109,7 @@ async fn sync_download(
for i in remote_status.deleted {
// we will update the stored history to have this data
// pretty much everything can be nullified
- if let Ok(h) = db.load(i.as_str()).await {
+ if let Some(h) = db.load(i.as_str()).await? {
db.delete(h).await?;
} else {
info!(