diff --git a/crates/binary-cookies/CHANGELOG.md b/crates/binary-cookies/CHANGELOG.md new file mode 100644 index 0000000..1276a5d --- /dev/null +++ b/crates/binary-cookies/CHANGELOG.md @@ -0,0 +1,14 @@ + + +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Changed + +- Better error handle diff --git a/crates/binary-cookies/src/error.rs b/crates/binary-cookies/src/error.rs index a01bbe3..7bfa6c8 100644 --- a/crates/binary-cookies/src/error.rs +++ b/crates/binary-cookies/src/error.rs @@ -8,31 +8,31 @@ use winnow::error::ContextError; #[derive(Snafu)] #[snafu(visibility(pub))] pub enum ParseError { - #[snafu(display("{render}, @:{location}"))] + #[snafu(display("{render}\n@:{location}"))] WinnowCtx { render: ContextError, #[snafu(implicit)] location: Location, }, - #[snafu(display("Time broken: {local_result:?}, @:{location}"))] + #[snafu(display("Time broken: {local_result:?}\n@:{location}"))] Time { local_result: LocalResult>, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Bplist { source: BplistErr, #[snafu(implicit)] location: Location, }, - #[snafu(display("Read: {source}, @:{location}",))] + #[snafu(display("Read: {source}\n@:{location}",))] Read { source: std::io::Error, #[snafu(implicit)] location: Location, }, - #[snafu(display("End of binarycookies, can't decode any more data, @:{location}"))] + #[snafu(display("End of binarycookies, can't decode any more data\n@:{location}"))] ParsingCompleted { #[snafu(implicit)] location: Location, @@ -50,24 +50,27 @@ impl ParseError { #[derive(Snafu)] #[snafu(visibility(pub))] pub enum BplistErr { - #[snafu(display(r#"Not start with b"bplist00", @:{location}"#))] + #[snafu(display( + r#"Not start with b"bplist00" +@:{location}"# + ))] Magic { #[snafu(implicit)] location: Location, }, - #[snafu(display(r#"The object not dict, need update decoder, @:{location}"#))] + #[snafu(display("The object not dict, need update decoder\n@:{location}"))] NotDict { #[snafu(implicit)] location: Location, }, #[snafu(display( - r#"The dict key not `NSHTTPCookieAcceptPolicy`, need update decoder, @:{location}"# + "The dict key not `NSHTTPCookieAcceptPolicy`, need update decoder\n@:{location}" ))] BadKey { #[snafu(implicit)] location: Location, }, - #[snafu(display(r#"The int not one byte, need update decoder, @:{location}"#))] + #[snafu(display("The int not one byte, need update decoder\n@:{location}"))] OneByteInt { #[snafu(implicit)] location: Location, diff --git a/crates/chromium-crypto/CHANGELOG.md b/crates/chromium-crypto/CHANGELOG.md index 384647c..0813c32 100644 --- a/crates/chromium-crypto/CHANGELOG.md +++ b/crates/chromium-crypto/CHANGELOG.md @@ -7,6 +7,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Changed + +- Better error handle + ## [0.2.0] - 2025-07-27 ### Changed diff --git a/crates/chromium-crypto/src/error.rs b/crates/chromium-crypto/src/error.rs index 09b8777..186295e 100644 --- a/crates/chromium-crypto/src/error.rs +++ b/crates/chromium-crypto/src/error.rs @@ -5,13 +5,13 @@ use snafu::{Location, Snafu}; #[snafu(visibility(pub))] #[cfg(target_os = "linux")] pub enum CryptoError { - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] GetPass { source: secret_service::Error, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Unpadding { source: aes::cipher::block_padding::UnpadError, #[snafu(implicit)] @@ -24,19 +24,19 @@ pub enum CryptoError { #[snafu(visibility(pub))] #[cfg(target_os = "macos")] pub enum CryptoError { - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Keyring { source: keyring::Error, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Unpadding { source: aes::cipher::block_padding::UnpadError, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Task { source: tokio::task::JoinError, #[snafu(implicit)] @@ -49,76 +49,76 @@ pub enum CryptoError { #[snafu(visibility(pub))] #[cfg(target_os = "windows")] pub enum CryptoError { - #[snafu(display("{source}, path: {}, @:{location}",path.display()))] + #[snafu(display("{source}, path: {}\n@:{location}",path.display()))] Io { source: std::io::Error, path: std::path::PathBuf, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Serde { source: serde_json::Error, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Base64 { source: base64::DecodeError, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Task { source: tokio::task::JoinError, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] AesGcm { source: aes_gcm::Error, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] CryptUnprotectData { source: windows::core::Error, #[snafu(implicit)] location: Location, }, - #[snafu(display("CryptUnprotectData returned a null pointer, @:{location}"))] + #[snafu(display("CryptUnprotectData returned a null pointer\n@:{location}"))] CryptUnprotectDataNull { #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] ChaCha { source: chacha20poly1305::Error, #[snafu(implicit)] location: Location, }, - #[snafu(display("{render}, @:{location}"))] + #[snafu(display("{render}\n@:{location}"))] Context { render: winnow::error::ContextError, #[snafu(implicit)] location: Location, }, - #[snafu(display(r#"app_bound_encrypted_key not start with "APPB", @:{location}"#))] + #[snafu(display(r#"app_bound_encrypted_key not start with "APPB"\n@:{location}"#))] Appb { #[snafu(implicit)] location: Location, }, - #[snafu(display("Get process path failed, @:{location}"))] + #[snafu(display("Get process path failed\n@:{location}"))] ProcessPath { #[snafu(implicit)] location: Location, }, - #[snafu(display("Invalid status from `RtlAdjustPrivilege`, @:{location}"))] + #[snafu(display("Invalid status from `RtlAdjustPrivilege`\n@:{location}"))] Privilege { #[snafu(implicit)] location: Location, }, - #[snafu(display("No such Process lsass.exe or winlogon.exe, @:{location}"))] + #[snafu(display("No such Process lsass.exe or winlogon.exe\n@:{location}"))] NotFoundProcess { #[snafu(implicit)] location: Location, diff --git a/crates/chromium-crypto/src/linux.rs b/crates/chromium-crypto/src/linux.rs index 47c7f30..1663d67 100644 --- a/crates/chromium-crypto/src/linux.rs +++ b/crates/chromium-crypto/src/linux.rs @@ -150,7 +150,7 @@ impl Decrypter { .map(|res| { String::from_utf8(res.to_vec()).unwrap_or_else(|_e| { #[cfg(feature = "tracing")] - tracing::info!("Decoding for chromium >= 130.x: {_e}"); + tracing::trace!("Decoding for chromium >= 130.x: {_e}"); String::from_utf8_lossy(&res[32..]).to_string() }) }) diff --git a/crates/chromium-crypto/src/mac.rs b/crates/chromium-crypto/src/mac.rs index 3444d30..bb3b595 100644 --- a/crates/chromium-crypto/src/mac.rs +++ b/crates/chromium-crypto/src/mac.rs @@ -86,7 +86,7 @@ impl Decrypter { .map(|res| { String::from_utf8(res.to_vec()).unwrap_or_else(|_e| { #[cfg(feature = "tracing")] - tracing::info!("Decoding for chromium >= 130.x: {_e}"); + tracing::trace!("Decoding for chromium >= 130.x: {_e}"); String::from_utf8_lossy(&res[32..]).to_string() }) }) diff --git a/crates/chromium-crypto/src/win/mod.rs b/crates/chromium-crypto/src/win/mod.rs index 9e21efd..2175f14 100644 --- a/crates/chromium-crypto/src/win/mod.rs +++ b/crates/chromium-crypto/src/win/mod.rs @@ -153,7 +153,7 @@ impl Decrypter { .map(|v| { String::from_utf8(v.clone()).unwrap_or_else(|_e| { #[cfg(feature = "tracing")] - tracing::info!("Decoding for chromium >=130.x: {_e}"); + tracing::trace!("Decoding for chromium >=130.x: {_e}"); String::from_utf8_lossy(&v[32..]).into_owned() }) }) diff --git a/crates/decrypt-cookies/CHANGELOG.md b/crates/decrypt-cookies/CHANGELOG.md index bc040c2..77e9c52 100644 --- a/crates/decrypt-cookies/CHANGELOG.md +++ b/crates/decrypt-cookies/CHANGELOG.md @@ -7,6 +7,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Changed + +- Better error handle + ## [0.8.0] - 2025-07-27 ### Changed @@ -18,7 +24,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - SafariGetter: add `cookies_by_host`. - ## [0.7.0] - 2025-07-20 ### Changed diff --git a/crates/decrypt-cookies/src/chromium/builder.rs b/crates/decrypt-cookies/src/chromium/builder.rs index 2c8e059..9a0ed5f 100644 --- a/crates/decrypt-cookies/src/chromium/builder.rs +++ b/crates/decrypt-cookies/src/chromium/builder.rs @@ -21,38 +21,46 @@ use crate::{ #[derive(Snafu)] #[snafu(visibility(pub))] pub enum ChromiumBuilderError { - #[snafu(display("{source}, @:{location}"))] + #[snafu(display(r#"Not found {} +The browser is not installed or started with `--user-data-dir` arg +@:{location}"#, path.display()))] + NotFoundBase { + path: PathBuf, + #[snafu(implicit)] + location: Location, + }, + #[snafu(display("{source}\n@:{location}"))] Decrypter { source: chromium_crypto::error::CryptoError, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Db { source: sea_orm::DbErr, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, path: {}, @:{location}",path.display()))] + #[snafu(display("{source}, path: {}\n@:{location}",path.display()))] Io { source: std::io::Error, path: PathBuf, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Rawcopy { source: anyhow::Error, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] TokioJoin { source: tokio::task::JoinError, #[snafu(implicit)] location: Location, }, - #[snafu(display("Can not found home dir, @:{location}"))] + #[snafu(display("Can not found home dir\n@:{location}"))] Home { #[snafu(implicit)] location: Location, @@ -131,6 +139,10 @@ impl ChromiumBuilder { tracing::debug!(base = %base.display()); }; + if !base.exists() { + return Err(NotFoundBaseSnafu { path: base }.build()); + } + let temp_paths = Self::cache_data(base).await?; #[cfg(target_os = "linux")] diff --git a/crates/decrypt-cookies/src/chromium/items/cookie/cookie_dao.rs b/crates/decrypt-cookies/src/chromium/items/cookie/cookie_dao.rs index 9bd440f..a3e8482 100644 --- a/crates/decrypt-cookies/src/chromium/items/cookie/cookie_dao.rs +++ b/crates/decrypt-cookies/src/chromium/items/cookie/cookie_dao.rs @@ -1,14 +1,14 @@ use std::path::Path; use sea_orm::{ - sea_query::IntoCondition, ColumnTrait, Database, DatabaseConnection, DbErr, EntityTrait, - QueryFilter, + sea_query::IntoCondition, ColumnTrait, DatabaseConnection, DbErr, EntityTrait, QueryFilter, }; use super::cookie_entities::{ cookies::{self, Model}, prelude::*, }; +use crate::utils::connect_db; type Result = std::result::Result; @@ -21,9 +21,7 @@ pub struct CookiesQuery { impl CookiesQuery { pub async fn new + Send>(path: P) -> Result { - let db_url = format!("sqlite:{}?mode=ro", path.as_ref().to_string_lossy()); - - let db = Database::connect(db_url).await?; + let db = connect_db(path).await?; Ok(Self { conn: db }) } diff --git a/crates/decrypt-cookies/src/chromium/items/passwd/login_data_dao.rs b/crates/decrypt-cookies/src/chromium/items/passwd/login_data_dao.rs index a75e4ae..8a8ddc6 100644 --- a/crates/decrypt-cookies/src/chromium/items/passwd/login_data_dao.rs +++ b/crates/decrypt-cookies/src/chromium/items/passwd/login_data_dao.rs @@ -3,10 +3,11 @@ use std::path::Path; use sea_orm::{ prelude::{DatabaseConnection, EntityTrait, QueryFilter}, sea_query::IntoCondition, - Database, DbErr, + DbErr, }; use super::login_data_entities::{logins, prelude::Logins}; +use crate::utils::connect_db; type Result = std::result::Result; @@ -19,9 +20,7 @@ pub struct LoginDataQuery { impl LoginDataQuery { pub async fn new + Send>(path: P) -> Result { - let db_url = format!("sqlite:{}?mode=ro", path.as_ref().to_string_lossy()); - - let db = Database::connect(db_url).await?; + let db = connect_db(path).await?; Ok(Self { conn: db }) } diff --git a/crates/decrypt-cookies/src/chromium/mod.rs b/crates/decrypt-cookies/src/chromium/mod.rs index 569e0da..20fbd10 100644 --- a/crates/decrypt-cookies/src/chromium/mod.rs +++ b/crates/decrypt-cookies/src/chromium/mod.rs @@ -35,19 +35,19 @@ use crate::{ #[derive(Snafu)] #[snafu(visibility(pub))] pub enum ChromiumError { - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Task { source: JoinError, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Db { source: DbErr, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Decrypt { source: chromium_crypto::error::CryptoError, #[snafu(implicit)] diff --git a/crates/decrypt-cookies/src/firefox/builder.rs b/crates/decrypt-cookies/src/firefox/builder.rs index ccfe3c0..bc7e05c 100644 --- a/crates/decrypt-cookies/src/firefox/builder.rs +++ b/crates/decrypt-cookies/src/firefox/builder.rs @@ -13,44 +13,52 @@ use crate::{ #[derive(Snafu)] #[snafu(visibility(pub))] pub enum FirefoxBuilderError { - #[snafu(display("{source}, @:{location}"))] + #[snafu(display(r#"Not found {} +The browser is not installed or started with `-P`/`-profile` arg +@:{location}"#, path.display()))] + NotFoundBase { + path: PathBuf, + #[snafu(implicit)] + location: Location, + }, + #[snafu(display("{source}\n@:{location}"))] Ini { source: ini::Error, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] IniParser { source: ini::ParseError, #[snafu(implicit)] location: Location, }, - #[snafu(display("Profile {profile} missing `Name` properties, @:{location}"))] + #[snafu(display("Profile {profile} missing `Name` properties\n@:{location}"))] ProfilePath { profile: String, #[snafu(implicit)] location: Location, }, - #[snafu(display("Install {install} missing `Default` properties, @:{location}"))] + #[snafu(display("Install {install} missing `Default` properties\n@:{location}"))] InstallPath { install: String, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Db { source: sea_orm::DbErr, #[snafu(implicit)] location: Location, }, - #[snafu(display("Io: {source}, path: {}, @:{location}",path.display()))] + #[snafu(display("Io: {source}, path: {}\n@:{location}",path.display()))] Io { source: std::io::Error, path: PathBuf, #[snafu(implicit)] location: Location, }, - #[snafu(display("Can not found home dir, @:{location}"))] + #[snafu(display("Can not found home dir\n@:{location}"))] Home { #[snafu(implicit)] location: Location, diff --git a/crates/decrypt-cookies/src/firefox/items/cookie/dao.rs b/crates/decrypt-cookies/src/firefox/items/cookie/dao.rs index 56acf54..8c347e2 100644 --- a/crates/decrypt-cookies/src/firefox/items/cookie/dao.rs +++ b/crates/decrypt-cookies/src/firefox/items/cookie/dao.rs @@ -1,14 +1,14 @@ use std::path::Path; use sea_orm::{ - sea_query::IntoCondition, ColumnTrait, Database, DatabaseConnection, DbErr, EntityTrait, - QueryFilter, + sea_query::IntoCondition, ColumnTrait, DatabaseConnection, DbErr, EntityTrait, QueryFilter, }; use super::entities::{ moz_cookies::{self, Model}, prelude::*, }; +use crate::utils::connect_db; type Result = std::result::Result; @@ -25,9 +25,7 @@ impl CookiesQuery { where P: AsRef + Send, { - let db_url = format!("sqlite:{}?mode=ro", path.as_ref().to_string_lossy()); - - let db = Database::connect(db_url).await?; + let db = connect_db(path).await?; Ok(Self { conn: db }) } diff --git a/crates/decrypt-cookies/src/firefox/mod.rs b/crates/decrypt-cookies/src/firefox/mod.rs index b471308..e527239 100644 --- a/crates/decrypt-cookies/src/firefox/mod.rs +++ b/crates/decrypt-cookies/src/firefox/mod.rs @@ -21,7 +21,7 @@ use crate::browser::cookies::LeetCodeCookies; #[derive(Snafu)] #[snafu(visibility(pub))] pub enum FirefoxError { - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Db { source: DbErr, #[snafu(implicit)] diff --git a/crates/decrypt-cookies/src/safari/mod.rs b/crates/decrypt-cookies/src/safari/mod.rs index 3cb9e9b..efbd77d 100644 --- a/crates/decrypt-cookies/src/safari/mod.rs +++ b/crates/decrypt-cookies/src/safari/mod.rs @@ -12,26 +12,26 @@ use crate::browser::cookies::LeetCodeCookies; #[derive(Snafu)] #[snafu(visibility(pub))] pub enum SafariError { - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Parse { source: binary_cookies::error::ParseError, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, path: {}, @:{location}",path.display()))] + #[snafu(display("{source}, path: {}\n@:{location}",path.display()))] Io { path: PathBuf, source: std::io::Error, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Task { source: tokio::task::JoinError, #[snafu(implicit)] location: Location, }, - #[snafu(display("Can not found home dir, @:{location}"))] + #[snafu(display("Can not found home dir\n@:{location}"))] Home { #[snafu(implicit)] location: Location, diff --git a/crates/decrypt-cookies/src/utils/mod.rs b/crates/decrypt-cookies/src/utils/mod.rs index 4355f8f..62e8ec4 100644 --- a/crates/decrypt-cookies/src/utils/mod.rs +++ b/crates/decrypt-cookies/src/utils/mod.rs @@ -1,11 +1,27 @@ use std::path::Path; +use sea_orm::{ConnectOptions, Database, DatabaseConnection, DbErr}; + pub fn need_sep(path: &Path) -> bool { let buf = path.as_os_str().as_encoded_bytes(); buf.last() .is_some_and(|&c| char::from(c) != std::path::MAIN_SEPARATOR) } +pub async fn connect_db + Send>( + path: P, +) -> std::result::Result { + let db_url = format!("sqlite:{}?mode=ro", path.as_ref().display()); + let mut opt = ConnectOptions::new(db_url); + opt.sqlx_logging_level( + "trace" + .parse() + .expect("Should not failed"), + ); + + Database::connect(opt).await +} + #[cfg(target_os = "windows")] pub fn shadow_copy(from: &Path, to: &Path) -> crate::chromium::builder::Result<()> { // shadow copy `to` must is dir diff --git a/crates/tidy-browser/CHANGELOG.md b/crates/tidy-browser/CHANGELOG.md index 33cc953..6ff7fe0 100644 --- a/crates/tidy-browser/CHANGELOG.md +++ b/crates/tidy-browser/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +- Subcommand: binary-cookies +- Output format json, jsonlines + ## [0.2.0] - 2025-07-27 ### Added diff --git a/crates/tidy-browser/src/chromium.rs b/crates/tidy-browser/src/chromium.rs index 2e40bf2..c8b4668 100644 --- a/crates/tidy-browser/src/chromium.rs +++ b/crates/tidy-browser/src/chromium.rs @@ -1,6 +1,6 @@ use std::{collections::HashSet, fmt::Display, fs::File, io::IoSlice, path::PathBuf}; -use decrypt_cookies::prelude::*; +use decrypt_cookies::{chromium::builder::ChromiumBuilderError, prelude::*}; use snafu::ResultExt; use strum::IntoEnumIterator; use tokio::task; @@ -43,8 +43,26 @@ impl ChromiumBased { Self::write_data(name, None, host, values, output_dir, sep, format).await }) }) { - task.await - .context(error::TokioTaskSnafu)??; + if let Err(e) = task + .await + .context(error::TokioTaskSnafu)? + { + match e { + error::Error::ChromiumBuilder { + source: source @ ChromiumBuilderError::NotFoundBase { .. }, + .. + } => { + #[cfg(not(target_os = "windows"))] + tracing::info!(r#"{source}"#,); + #[cfg(target_os = "windows")] + tracing::info!( + r#"{source} +When you use scoop on Windows, the data path is located at `~\scoop\persisst\\`"#, + ); + }, + e => tracing::error!("{e}"), + } + } } Ok(()) @@ -72,6 +90,7 @@ impl ChromiumBased { match name { $( ChromiumName::$browser => { + tracing::Span::current().record("browser", $browser::NAME); let chromium = if let Some(dir) = data_dir { ChromiumBuilder::<$browser>::with_user_data_dir(dir) } diff --git a/crates/tidy-browser/src/cli.rs b/crates/tidy-browser/src/cli.rs index b3167bf..f6f7d80 100644 --- a/crates/tidy-browser/src/cli.rs +++ b/crates/tidy-browser/src/cli.rs @@ -76,7 +76,10 @@ pub async fn run_cli(args: crate::args::Args) -> Result<()> { c.context(error::TokioTaskSnafu)??; f.context(error::TokioTaskSnafu)??; #[cfg(target_os = "macos")] - s.context(error::TokioTaskSnafu)??; + if let Err(e) = s.context(error::TokioTaskSnafu)? { + // With arg `-a` just print error + tracing::error!("{e}"); + } return Ok(()); } diff --git a/crates/tidy-browser/src/error.rs b/crates/tidy-browser/src/error.rs index e3ba003..8e29d52 100644 --- a/crates/tidy-browser/src/error.rs +++ b/crates/tidy-browser/src/error.rs @@ -12,57 +12,57 @@ use snafu::{Location, Snafu}; #[derive(Debug)] #[snafu(visibility(pub))] pub enum Error { - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] Json { source: serde_json::Error, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] BinaryCookies { source: binary_cookies::error::ParseError, #[snafu(implicit)] location: Location, }, - #[snafu(display("Build Chromium: {source}, @:{location}"))] + #[snafu(display("Build Chromium: {source}\n@:{location}"))] ChromiumBuilder { source: ChromiumBuilderError, #[snafu(implicit)] location: Location, }, - #[snafu(display("Chromium: {source}, @:{location}"))] + #[snafu(display("Chromium: {source}\n@:{location}"))] Chromium { source: ChromiumError, #[snafu(implicit)] location: Location, }, - #[snafu(display("Build Firefox: {source}, @:{location}"))] + #[snafu(display("Build Firefox: {source}\n@:{location}"))] FirefoxBuilder { source: FirefoxBuilderError, #[snafu(implicit)] location: Location, }, - #[snafu(display("Firefox: {source}, @:{location}"))] + #[snafu(display("Firefox: {source}\n@:{location}"))] Firefox { source: FirefoxError, #[snafu(implicit)] location: Location, }, #[cfg(target_os = "macos")] - #[snafu(display("Firefox: {source}, @:{location}"))] + #[snafu(display("Firefox: {source}\n@:{location}"))] Safari { source: SafariError, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source} path: {}, @:{location}", path.display()))] + #[snafu(display("{source} path: {}\n@:{location}", path.display()))] Io { source: std::io::Error, path: PathBuf, #[snafu(implicit)] location: Location, }, - #[snafu(display("{source}, @:{location}"))] + #[snafu(display("{source}\n@:{location}"))] TokioTask { source: tokio::task::JoinError, #[snafu(implicit)] diff --git a/crates/tidy-browser/src/firefox.rs b/crates/tidy-browser/src/firefox.rs index 02f2484..a417a6b 100644 --- a/crates/tidy-browser/src/firefox.rs +++ b/crates/tidy-browser/src/firefox.rs @@ -1,6 +1,6 @@ use std::{collections::HashSet, fmt::Display, path::PathBuf}; -use decrypt_cookies::prelude::*; +use decrypt_cookies::{firefox::builder::FirefoxBuilderError, prelude::*}; use snafu::ResultExt; use strum::IntoEnumIterator; use tokio::task; @@ -42,13 +42,31 @@ impl FirefoxBased { .await }) }) { - task.await - .context(error::TokioTaskSnafu)??; + if let Err(e) = task + .await + .context(error::TokioTaskSnafu)? + { + match e { + error::Error::FirefoxBuilder { + source: FirefoxBuilderError::NotFoundBase { path, .. }, + .. + } => { + tracing::info!( + r#"Not found {}, +The browser is not installed or started with `-P`/`-profile` arg."#, + path.display() + ); + todo!() + }, + e => tracing::error!("{e}"), + } + } } Ok(()) } + #[tracing::instrument(skip_all, fields(name), level = "info")] #[expect(clippy::too_many_arguments, reason = "bin not lib")] pub async fn write_data( name: FirefoxName, diff --git a/crates/tidy-browser/src/main.rs b/crates/tidy-browser/src/main.rs index b908f17..d836199 100644 --- a/crates/tidy-browser/src/main.rs +++ b/crates/tidy-browser/src/main.rs @@ -2,6 +2,7 @@ use clap::Parser; use tidy_browser::args::{self}; use tracing_subscriber::EnvFilter; +#[snafu::report] #[tokio::main] async fn main() -> tidy_browser::error::Result<()> { tracing_subscriber::fmt()