mirror of
https://github.com/NotAShelf/stash.git
synced 2026-04-13 14:33:47 +00:00
treewide: improve logging; custom error types with thiserror
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I6a6a696464e4123d15cfaedf4727776e55948369
This commit is contained in:
parent
7dd3db4c88
commit
6e21021306
10 changed files with 221 additions and 166 deletions
|
|
@ -2,13 +2,26 @@ use crate::db::{ClipboardDb, SledClipboardDb};
|
|||
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use crate::db::StashError;
|
||||
|
||||
pub trait DecodeCommand {
|
||||
fn decode(&self, in_: impl Read, out: impl Write, input: Option<String>);
|
||||
fn decode(
|
||||
&self,
|
||||
in_: impl Read,
|
||||
out: impl Write,
|
||||
input: Option<String>,
|
||||
) -> Result<(), StashError>;
|
||||
}
|
||||
|
||||
impl DecodeCommand for SledClipboardDb {
|
||||
fn decode(&self, in_: impl Read, out: impl Write, input: Option<String>) {
|
||||
self.decode_entry(in_, out, input);
|
||||
fn decode(
|
||||
&self,
|
||||
in_: impl Read,
|
||||
out: impl Write,
|
||||
input: Option<String>,
|
||||
) -> Result<(), StashError> {
|
||||
self.decode_entry(in_, out, input)?;
|
||||
log::info!("Entry decoded");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,22 @@
|
|||
use crate::db::{ClipboardDb, SledClipboardDb};
|
||||
use crate::db::{ClipboardDb, SledClipboardDb, StashError};
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
pub trait DeleteCommand {
|
||||
fn delete(&self, input: impl Read);
|
||||
fn delete(&self, input: impl Read) -> Result<usize, StashError>;
|
||||
}
|
||||
|
||||
impl DeleteCommand for SledClipboardDb {
|
||||
fn delete(&self, input: impl Read) {
|
||||
self.delete_entries(input);
|
||||
log::info!("Entries deleted");
|
||||
fn delete(&self, input: impl Read) -> Result<usize, StashError> {
|
||||
match self.delete_entries(input) {
|
||||
Ok(deleted) => {
|
||||
log::info!("Deleted {} entries", deleted);
|
||||
Ok(deleted)
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to delete entries: {}", e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@ use crate::db::{ClipboardDb, SledClipboardDb};
|
|||
use std::io::Write;
|
||||
|
||||
pub trait ListCommand {
|
||||
fn list(&self, out: impl Write, preview_width: u32);
|
||||
fn list(&self, out: impl Write, preview_width: u32) -> Result<(), crate::db::StashError>;
|
||||
}
|
||||
|
||||
impl ListCommand for SledClipboardDb {
|
||||
fn list(&self, out: impl Write, preview_width: u32) {
|
||||
self.list_entries(out, preview_width);
|
||||
log::info!("Entries listed");
|
||||
fn list(&self, out: impl Write, preview_width: u32) -> Result<(), crate::db::StashError> {
|
||||
self.list_entries(out, preview_width)?;
|
||||
log::info!("Listed clipboard entries");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
use crate::db::{ClipboardDb, SledClipboardDb};
|
||||
|
||||
use crate::db::StashError;
|
||||
|
||||
pub trait QueryCommand {
|
||||
fn query_delete(&self, query: &str);
|
||||
fn query_delete(&self, query: &str) -> Result<usize, StashError>;
|
||||
}
|
||||
|
||||
impl QueryCommand for SledClipboardDb {
|
||||
fn query_delete(&self, query: &str) {
|
||||
<SledClipboardDb as ClipboardDb>::delete_query(self, query);
|
||||
log::info!("Entries matching query '{}' deleted", query);
|
||||
fn query_delete(&self, query: &str) -> Result<usize, StashError> {
|
||||
<SledClipboardDb as ClipboardDb>::delete_query(self, query)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ pub trait StoreCommand {
|
|||
max_dedupe_search: u64,
|
||||
max_items: u64,
|
||||
state: Option<String>,
|
||||
);
|
||||
) -> Result<(), crate::db::StashError>;
|
||||
}
|
||||
|
||||
impl StoreCommand for SledClipboardDb {
|
||||
|
|
@ -19,13 +19,14 @@ impl StoreCommand for SledClipboardDb {
|
|||
max_dedupe_search: u64,
|
||||
max_items: u64,
|
||||
state: Option<String>,
|
||||
) {
|
||||
) -> Result<(), crate::db::StashError> {
|
||||
if let Some("sensitive" | "clear") = state.as_deref() {
|
||||
self.delete_last();
|
||||
self.delete_last()?;
|
||||
log::info!("Entry deleted");
|
||||
} else {
|
||||
self.store_entry(input, max_dedupe_search, max_items);
|
||||
self.store_entry(input, max_dedupe_search, max_items)?;
|
||||
log::info!("Entry stored");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
use crate::db::{ClipboardDb, SledClipboardDb};
|
||||
|
||||
use crate::db::StashError;
|
||||
|
||||
pub trait WipeCommand {
|
||||
fn wipe(&self);
|
||||
fn wipe(&self) -> Result<(), StashError>;
|
||||
}
|
||||
|
||||
impl WipeCommand for SledClipboardDb {
|
||||
fn wipe(&self) {
|
||||
self.wipe_db();
|
||||
fn wipe(&self) -> Result<(), StashError> {
|
||||
self.wipe_db()?;
|
||||
log::info!("Database wiped");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue