replace anyhow and log with color_eyre and tracing

Since Himalaya is intended to be ran as a CLI in the terminal emulator
environment, their user experience could vastly improve with better and
more colorful error messages and logging.

This change will replace more minimal libraries for error-reporting/han-
dling with their more advanced counterparts.

Since these crates have tight integrations, this commit will change both
in one shot.

Also we have don't need env_logger any more. So I also have removed that
guy as well.

Signed-off-by: Perma Alesheikh <me@prma.dev>
This commit is contained in:
Perma Alesheikh 2024-04-15 00:10:46 +03:30 committed by Clément DOUIN
parent cc79f5cc38
commit 5a0ff83a5e
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
68 changed files with 376 additions and 198 deletions

236
Cargo.lock generated
View file

@ -153,12 +153,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "anyhow"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247"
[[package]]
name = "ariadne"
version = "0.2.0"
@ -346,17 +340,6 @@ version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi 0.1.19",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.2.0"
@ -722,6 +705,33 @@ dependencies = [
"roff",
]
[[package]]
name = "color-eyre"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]]
name = "colorchoice"
version = "1.0.0"
@ -1218,8 +1228,7 @@ dependencies = [
[[package]]
name = "email-lib"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28526bad9d46fcfb2c6385961aeb4b684546c965d18a12e5552ca4af7cf1f35e"
source = "git+https://git.sr.ht/~soywod/pimalaya#7d56cfda13fe13a9aa48d9a117573e3dfbbcf8a2"
dependencies = [
"advisory-lock",
"async-trait",
@ -1268,8 +1277,7 @@ dependencies = [
[[package]]
name = "email-macros"
version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f24a09fd651027f8764f8a12c12358715cb9bab622ab3125ede3dd6ae047c95"
source = "git+https://git.sr.ht/~soywod/pimalaya#7d56cfda13fe13a9aa48d9a117573e3dfbbcf8a2"
dependencies = [
"quote",
"syn 2.0.58",
@ -1332,19 +1340,6 @@ dependencies = [
"syn 2.0.58",
]
[[package]]
name = "env_logger"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "equivalent"
version = "1.0.1"
@ -1429,6 +1424,16 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "eyre"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec"
dependencies = [
"indenter",
"once_cell",
]
[[package]]
name = "fastrand"
version = "1.9.0"
@ -1793,15 +1798,6 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.3.9"
@ -1869,24 +1865,22 @@ dependencies = [
name = "himalaya"
version = "1.0.0-beta.4"
dependencies = [
"anyhow",
"ariadne",
"async-trait",
"chrono",
"clap",
"clap_complete",
"clap_mangen",
"color-eyre",
"console",
"coredump",
"dialoguer",
"dirs 4.0.0",
"email-lib",
"email_address",
"env_logger",
"erased-serde",
"indicatif",
"keyring-lib",
"log",
"mail-builder",
"md5",
"mml-lib",
@ -1905,6 +1899,9 @@ dependencies = [
"tokio",
"toml",
"toml_edit 0.22.9",
"tracing",
"tracing-error",
"tracing-subscriber",
"unicode-width",
"url",
"uuid",
@ -1982,12 +1979,6 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "hyper"
version = "0.14.28"
@ -2112,6 +2103,12 @@ dependencies = [
"nom",
]
[[package]]
name = "indenter"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]]
name = "indexmap"
version = "2.2.6"
@ -2179,7 +2176,7 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
dependencies = [
"hermit-abi 0.3.9",
"hermit-abi",
"libc",
"windows-sys 0.48.0",
]
@ -2258,8 +2255,7 @@ dependencies = [
[[package]]
name = "keyring-lib"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2e6d01e57f1b382ba5a1c40ef866855e8bab15f7caa4033480db80a5b9b9aff"
source = "git+https://git.sr.ht/~soywod/pimalaya#7d56cfda13fe13a9aa48d9a117573e3dfbbcf8a2"
dependencies = [
"keyring",
"log",
@ -2482,6 +2478,15 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4"
[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata 0.1.10",
]
[[package]]
name = "md-5"
version = "0.10.6"
@ -2558,8 +2563,7 @@ dependencies = [
[[package]]
name = "mml-lib"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3c6ac41c419e7857fdf7104a2f750c0d575969fa32f50a9d370ea3a3bcab1bf"
source = "git+https://git.sr.ht/~soywod/pimalaya#7d56cfda13fe13a9aa48d9a117573e3dfbbcf8a2"
dependencies = [
"async-recursion",
"chumsky",
@ -2645,6 +2649,16 @@ dependencies = [
"libc",
]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]
[[package]]
name = "num"
version = "0.4.1"
@ -2762,7 +2776,7 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [
"hermit-abi 0.3.9",
"hermit-abi",
"libc",
]
@ -2775,8 +2789,7 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "oauth-lib"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fd81f50b3bdf9656f511a776e5a76c249e00d7ce5c0c9071d0b923177d9248d"
source = "git+https://git.sr.ht/~soywod/pimalaya#7d56cfda13fe13a9aa48d9a117573e3dfbbcf8a2"
dependencies = [
"log",
"oauth2",
@ -2935,6 +2948,18 @@ dependencies = [
"syn 2.0.58",
]
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "owo-colors"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "p256"
version = "0.13.2"
@ -3220,7 +3245,7 @@ checksum = "e0c976a60b2d7e99d6f229e414670a9b85d13ac305cc6d1e9c134de58c5aaaf6"
dependencies = [
"cfg-if",
"concurrent-queue",
"hermit-abi 0.3.9",
"hermit-abi",
"pin-project-lite",
"rustix 0.38.32",
"tracing",
@ -3313,8 +3338,7 @@ dependencies = [
[[package]]
name = "process-lib"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0600893efc62c84ded38fec2b022ada4d4d80e48a8df5bceb070c865bf8a33a9"
source = "git+https://git.sr.ht/~soywod/pimalaya#7d56cfda13fe13a9aa48d9a117573e3dfbbcf8a2"
dependencies = [
"log",
"serde",
@ -3446,6 +3470,15 @@ dependencies = [
"regex-syntax 0.8.3",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax 0.6.29",
]
[[package]]
name = "regex-automata"
version = "0.3.9"
@ -3468,6 +3501,12 @@ dependencies = [
"regex-syntax 0.8.3",
]
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
name = "regex-syntax"
version = "0.7.5"
@ -3815,8 +3854,7 @@ dependencies = [
[[package]]
name = "secret-lib"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d99d0df4b8cb27c13c953abaf74bd089922a783fad99cd2b08b369cf7fabcbc9"
source = "git+https://git.sr.ht/~soywod/pimalaya#7d56cfda13fe13a9aa48d9a117573e3dfbbcf8a2"
dependencies = [
"keyring-lib",
"log",
@ -3999,6 +4037,15 @@ dependencies = [
"keccak",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "shell-words"
version = "1.1.0"
@ -4019,8 +4066,7 @@ dependencies = [
[[package]]
name = "shellexpand-utils"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c15a8f3693529b38d1be40ec6016bb6317ebee4a0208a813a75e3538f3e439f5"
source = "git+https://git.sr.ht/~soywod/pimalaya#7d56cfda13fe13a9aa48d9a117573e3dfbbcf8a2"
dependencies = [
"log",
"shellexpand",
@ -4284,6 +4330,16 @@ dependencies = [
"syn 2.0.58",
]
[[package]]
name = "thread_local"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "time"
version = "0.3.34"
@ -4463,6 +4519,46 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-error"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-log"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
dependencies = [
"log",
"once_cell",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [
"matchers",
"nu-ansi-term",
"once_cell",
"regex",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
]
[[package]]
@ -4594,6 +4690,12 @@ dependencies = [
"getrandom",
]
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "version-compare"
version = "0.2.0"

View file

@ -49,23 +49,21 @@ pgp-native = ["email-lib/pgp-native", "mml-lib/pgp-native", "pgp"]
tempfile = "3.3"
[dependencies]
anyhow = "1"
ariadne = "0.2"
async-trait = "0.1"
chrono = "0.4.24"
clap = { version = "4.4", features = ["derive"] }
clap_complete = "4.4"
clap_mangen = "0.2"
color-eyre = "0.6.3"
console = "0.15.2"
dialoguer = "0.10.2"
dirs = "4"
email-lib = { version = "=0.24.0", default-features = false, features = ["derive"] }
email_address = "0.2.4"
env_logger = "0.8"
erased-serde = "0.3"
indicatif = "0.17"
keyring-lib = { version = "=0.4.2", features = ["derive"] }
log = "0.4"
mail-builder = "0.3"
md5 = "0.7"
mml-lib = { version = "=1.0.12", default-features = false, features = ["derive"] }
@ -83,6 +81,9 @@ terminal_size = "0.1"
tokio = { version = "1.23", default-features = false, features = ["macros", "rt-multi-thread"] }
toml = "0.8"
toml_edit = "0.22"
tracing = "0.1.40"
tracing-error = "0.2.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
unicode-width = "0.1"
url = "2.2"
uuid = { version = "0.8", features = ["v4"] }

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::context::BackendContextBuilder;
use log::info;
use tracing::info;
use crate::{
account::arg::name::OptionalAccountNameArg, backend, config::TomlConfig, printer::Printer,

View file

@ -1,12 +1,12 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
#[cfg(feature = "imap")]
use email::imap::config::ImapAuthConfig;
#[cfg(feature = "smtp")]
use email::smtp::config::SmtpAuthConfig;
use log::info;
use tracing::info;
#[cfg(any(feature = "imap", feature = "smtp"))]
use log::{debug, warn};
use tracing::{debug, warn};
#[cfg(any(feature = "imap", feature = "smtp", feature = "pgp"))]
use crate::ui::prompt;

View file

@ -1,6 +1,6 @@
use anyhow::Result;
use clap::Parser;
use log::info;
use color_eyre::Result;
use tracing::info;
use crate::{
account::Accounts,

View file

@ -4,7 +4,7 @@ mod list;
#[cfg(feature = "account-sync")]
mod sync;
use anyhow::Result;
use color_eyre::Result;
use clap::Subcommand;
use crate::{config::TomlConfig, printer::Printer};

View file

@ -1,5 +1,5 @@
use anyhow::{anyhow, bail, Result};
use clap::{ArgAction, Parser};
use color_eyre::{eyre::bail, eyre::eyre, Result};
use email::backend::context::BackendContextBuilder;
#[cfg(feature = "imap")]
use email::imap::ImapContextBuilder;
@ -10,12 +10,12 @@ use email::{
sync::{hash::SyncHash, SyncEvent},
};
use indicatif::{MultiProgress, ProgressBar, ProgressFinish, ProgressStyle};
use log::info;
use once_cell::sync::Lazy;
use std::{
collections::{BTreeSet, HashMap},
sync::{Arc, Mutex},
};
use tracing::info;
use crate::{
account::arg::name::OptionalAccountNameArg, backend::BackendKind, config::TomlConfig,
@ -99,7 +99,7 @@ impl AccountSyncCommand {
.as_ref()
.map(Clone::clone)
.map(Arc::new)
.ok_or_else(|| anyhow!("imap config not found"))?;
.ok_or_else(|| eyre!("imap config not found"))?;
let imap_ctx = ImapContextBuilder::new(account_config.clone(), imap_config)
.with_prebuilt_credentials()
.await?;

View file

@ -3,7 +3,7 @@ pub mod command;
pub mod config;
pub(crate) mod wizard;
use anyhow::Result;
use color_eyre::Result;
use serde::Serialize;
use std::{collections::hash_map::Iter, fmt, ops::Deref};

View file

@ -1,6 +1,6 @@
#[cfg(feature = "account-sync")]
use crate::account::config::SyncConfig;
use anyhow::{bail, Result};
use color_eyre::{eyre::bail, Result};
#[cfg(feature = "account-sync")]
use dialoguer::Confirm;
use dialoguer::Input;

View file

@ -1,7 +1,7 @@
pub mod config;
pub(crate) mod wizard;
use anyhow::Result;
use color_eyre::Result;
use async_trait::async_trait;
use std::{ops::Deref, sync::Arc};

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use color_eyre::Result;
use dialoguer::Select;
#[cfg(feature = "account-discovery")]
use email::account::discover::config::AutoConfig;

8
src/cache/mod.rs vendored
View file

@ -1,11 +1,11 @@
pub mod arg;
use anyhow::{anyhow, Context, Result};
use color_eyre::{eyre::eyre, eyre::Context, Result};
use dirs::data_dir;
use email::account::config::AccountConfig;
use log::debug;
use sled::{Config, Db};
use std::collections::HashSet;
use tracing::debug;
#[derive(Debug)]
pub enum IdMapper {
@ -17,7 +17,7 @@ impl IdMapper {
pub fn new(account_config: &AccountConfig, folder: &str) -> Result<Self> {
let digest = md5::compute(account_config.name.clone() + folder);
let db_path = data_dir()
.ok_or(anyhow!("cannot get XDG data directory"))?
.ok_or(eyre!("cannot get XDG data directory"))?
.join("himalaya")
.join(".id-mappers")
.join(format!("{digest:x}"));
@ -108,7 +108,7 @@ impl IdMapper {
None
}
})
.ok_or_else(|| anyhow!("cannot get id from alias {alias}"))?;
.ok_or_else(|| eyre!("cannot get id from alias {alias}"))?;
debug!("found id {id} from alias {alias}");
Ok(id)

View file

@ -1,5 +1,5 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use color_eyre::Result;
use std::path::PathBuf;
use crate::{
@ -75,6 +75,20 @@ pub struct Cli {
#[arg(long, short = 'C', global = true)]
#[arg(value_name = "MODE", value_enum, default_value_t = Default::default())]
pub color: ColorFmt,
/// Enable logs with spantrace.
///
/// This is the same as running the command with `RUST_LOG=debug`
/// environment variable.
#[arg(long, global = true, conflicts_with = "trace")]
pub debug: bool,
/// Enable verbose logs with backtrace.
///
/// This is the same as running the command with `RUST_LOG=trace`
/// and `RUST_BACKTRACE=1` environment variables.
#[arg(long, global = true, conflicts_with = "debug")]
pub trace: bool,
}
#[derive(Subcommand, Debug)]

View file

@ -1,8 +1,8 @@
use anyhow::Result;
use clap::{value_parser, CommandFactory, Parser};
use clap_complete::Shell;
use log::info;
use color_eyre::Result;
use std::io;
use tracing::info;
use crate::cli::Cli;

View file

@ -1,17 +1,20 @@
pub mod wizard;
use anyhow::{anyhow, bail, Context, Result};
use color_eyre::{
eyre::{bail, eyre, Context},
Result,
};
use dirs::{config_dir, home_dir};
use email::{
account::config::AccountConfig, config::Config, envelope::config::EnvelopeConfig,
flag::config::FlagConfig, folder::config::FolderConfig, message::config::MessageConfig,
};
use log::debug;
use serde::{Deserialize, Serialize};
use serde_toml_merge::merge;
use shellexpand_utils::{canonicalize, expand};
use std::{collections::HashMap, fs, path::PathBuf, sync::Arc};
use toml::{self, Value};
use tracing::debug;
#[cfg(feature = "account-sync")]
use crate::backend::BackendKind;
@ -136,7 +139,7 @@ impl TomlConfig {
/// found.
pub fn default_path() -> Result<PathBuf> {
Ok(config_dir()
.ok_or(anyhow!("cannot get XDG config directory"))?
.ok_or(eyre!("cannot get XDG config directory"))?
.join("himalaya")
.join("config.toml"))
}
@ -175,12 +178,12 @@ impl TomlConfig {
.filter(|default| *default)
.map(|_| (name.to_owned(), account.clone()))
})
.ok_or_else(|| anyhow!("cannot find default account")),
.ok_or_else(|| eyre!("cannot find default account")),
Some(name) => self
.accounts
.get(name)
.map(|account| (name.to_owned(), account.clone()))
.ok_or_else(|| anyhow!("cannot find account {name}")),
.ok_or_else(|| eyre!("cannot find account {name}")),
}?;
#[cfg(feature = "imap")]

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use color_eyre::Result;
use dialoguer::{Confirm, Input, Select};
use shellexpand_utils::expand;
use std::{fs, path::PathBuf, process};

View file

@ -1,12 +1,12 @@
use anyhow::Result;
use ariadne::{Color, Label, Report, ReportKind, Source};
use clap::Parser;
use color_eyre::Result;
use email::{
backend::feature::BackendFeatureSource, email::search_query,
envelope::list::ListEnvelopesOptions, search_query::SearchEmailsQuery,
};
use log::info;
use std::process::exit;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,7 +1,7 @@
pub mod list;
pub mod watch;
use anyhow::Result;
use color_eyre::Result;
use clap::Subcommand;
use crate::{config::TomlConfig, printer::Printer};

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,6 +1,6 @@
use clap::Parser;
use email::flag::{Flag, Flags};
use log::debug;
use tracing::debug;
/// The ids and/or flags arguments parser.
#[derive(Debug, Parser)]

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -2,7 +2,7 @@ mod add;
mod remove;
mod set;
use anyhow::Result;
use color_eyre::Result;
use clap::Subcommand;
use crate::{config::TomlConfig, printer::Printer};

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -3,7 +3,7 @@ pub mod command;
pub mod config;
pub mod flag;
use anyhow::Result;
use color_eyre::Result;
use email::account::config::AccountConfig;
use serde::Serialize;
use std::ops;

View file

@ -1,8 +1,8 @@
use anyhow::{Context, Result};
use clap::Parser;
use color_eyre::{eyre::Context, Result};
use email::backend::feature::BackendFeatureSource;
use log::info;
use std::{fs, path::PathBuf};
use tracing::info;
use uuid::Uuid;
#[cfg(feature = "account-sync")]

View file

@ -1,6 +1,6 @@
mod download;
use anyhow::Result;
use color_eyre::Result;
use clap::Subcommand;
use crate::{config::TomlConfig, printer::Printer};

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use clap::Parser;
use color_eyre::{eyre::eyre, Result};
use email::backend::feature::BackendFeatureSource;
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;
@ -75,7 +75,7 @@ impl MessageForwardCommand {
.get_messages(folder, &[id])
.await?
.first()
.ok_or(anyhow!("cannot find message"))?
.ok_or(eyre!("cannot find message"))?
.to_forward_tpl_builder(account_config.clone())
.with_headers(self.headers.raw)
.with_body(self.body.raw())

View file

@ -1,8 +1,8 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use mail_builder::MessageBuilder;
use tracing::info;
use url::Url;
#[cfg(feature = "account-sync")]

View file

@ -9,7 +9,7 @@ pub mod save;
pub mod send;
pub mod write;
use anyhow::Result;
use color_eyre::Result;
use clap::Subcommand;
use crate::{config::TomlConfig, printer::Printer};

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,8 +1,8 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use mml::message::FilterParts;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use clap::Parser;
use color_eyre::{eyre::eyre, Result};
use email::backend::feature::BackendFeatureSource;
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;
@ -77,7 +77,7 @@ impl MessageReplyCommand {
.get_messages(folder, &[id])
.await?
.first()
.ok_or(anyhow!("cannot find message {id}"))?
.ok_or(eyre!("cannot find message {id}"))?
.to_reply_tpl_builder(account_config.clone())
.with_headers(self.headers.raw)
.with_body(self.body.raw())

View file

@ -1,8 +1,8 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use std::io::{self, BufRead, IsTerminal};
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,8 +1,8 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use std::io::{self, BufRead, IsTerminal};
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::{backend::feature::BackendFeatureSource, message::Message};
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use clap::Parser;
use color_eyre::{eyre::eyre, Result};
use email::backend::feature::BackendFeatureSource;
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;
@ -69,7 +69,7 @@ impl TemplateForwardCommand {
.get_messages(folder, &[id])
.await?
.first()
.ok_or(anyhow!("cannot find message {id}"))?
.ok_or(eyre!("cannot find message {id}"))?
.to_forward_tpl_builder(account_config)
.with_headers(self.headers.raw)
.with_body(self.body.raw())

View file

@ -4,7 +4,7 @@ mod save;
mod send;
mod write;
use anyhow::Result;
use color_eyre::Result;
use clap::Subcommand;
use crate::{config::TomlConfig, printer::Printer};

View file

@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use clap::Parser;
use color_eyre::{eyre::eyre, Result};
use email::backend::feature::BackendFeatureSource;
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;
@ -73,7 +73,7 @@ impl TemplateReplyCommand {
.get_messages(folder, &[id])
.await?
.first()
.ok_or(anyhow!("cannot find message {id}"))?
.ok_or(eyre!("cannot find message {id}"))?
.to_reply_tpl_builder(account_config)
.with_headers(self.headers.raw)
.with_body(self.body.raw())

View file

@ -1,9 +1,9 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use mml::MmlCompilerBuilder;
use std::io::{self, BufRead, IsTerminal};
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,9 +1,9 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::backend::feature::BackendFeatureSource;
use log::info;
use mml::MmlCompilerBuilder;
use std::io::{self, BufRead, IsTerminal};
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::message::Message;
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,7 +1,7 @@
pub mod arg;
pub mod command;
use anyhow::Result;
use color_eyre::Result;
use email::template::Template;
use crate::printer::{Print, WriteColor};

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::{backend::feature::BackendFeatureSource, folder::add::AddFolder};
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,9 +1,9 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use dialoguer::Confirm;
use email::{backend::feature::BackendFeatureSource, folder::delete::DeleteFolder};
use log::info;
use std::process;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::{backend::feature::BackendFeatureSource, folder::expunge::ExpungeFolder};
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use email::{backend::feature::BackendFeatureSource, folder::list::ListFolders};
use log::info;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -4,7 +4,7 @@ mod expunge;
mod list;
mod purge;
use anyhow::Result;
use color_eyre::Result;
use clap::Subcommand;
use crate::{config::TomlConfig, printer::Printer};

View file

@ -1,9 +1,9 @@
use anyhow::Result;
use clap::Parser;
use color_eyre::Result;
use dialoguer::Confirm;
use email::{backend::feature::BackendFeatureSource, folder::purge::PurgeFolder};
use log::info;
use std::process;
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;

View file

@ -2,7 +2,7 @@ pub mod arg;
pub mod command;
pub mod config;
use anyhow::Result;
use color_eyre::Result;
use serde::Serialize;
use std::ops;

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use color_eyre::Result;
use dialoguer::{Confirm, Input, Password, Select};
#[cfg(feature = "account-discovery")]
use email::account::discover::config::{AuthenticationType, AutoConfig, SecurityType, ServerType};

View file

@ -19,6 +19,7 @@ pub mod printer;
pub mod sendmail;
#[cfg(feature = "smtp")]
pub mod smtp;
pub mod tracing;
pub mod ui;
#[doc(inline)]

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use color_eyre::Result;
use dialoguer::Input;
use dirs::home_dir;
use email::maildir::config::MaildirConfig;

View file

@ -1,25 +1,35 @@
use anyhow::Result;
use std::env;
use clap::Parser;
use env_logger::{Builder as LoggerBuilder, Env, DEFAULT_FILTER_ENV};
use color_eyre::{Result, Section};
use himalaya::{
cli::Cli, config::TomlConfig, envelope::command::list::ListEnvelopesCommand,
message::command::mailto::MessageMailtoCommand, printer::StdoutPrinter,
};
use log::{debug, trace};
use tracing::{debug, level_filters::LevelFilter, trace};
#[tokio::main]
async fn main() -> Result<()> {
if env::var("RUST_LOG").is_err() {
if std::env::args().any(|arg| arg == "--debug") {
env::set_var("RUST_LOG", "debug");
}
if std::env::args().any(|arg| arg == "--trace") {
env::set_var("RUST_LOG", "trace");
}
}
let cli = Cli::parse();
let filter = himalaya::tracing::install()?;
let mut printer = StdoutPrinter::new(cli.output, cli.color);
#[cfg(not(target_os = "windows"))]
if let Err((_, err)) = coredump::register_panic_handler() {
debug!("cannot register coredump panic handler: {err}");
trace!("{err:?}");
trace!("cannot register coredump panic handler: {err}");
debug!("{err:?}");
}
LoggerBuilder::new()
.parse_env(Env::new().filter_or(DEFAULT_FILTER_ENV, "warn"))
.format_timestamp(None)
.init();
// if the first argument starts by "mailto:", execute straight the
// mailto message command
let mailto = std::env::args()
@ -35,10 +45,7 @@ async fn main() -> Result<()> {
.await;
}
let cli = Cli::parse();
let mut printer = StdoutPrinter::new(cli.output, cli.color);
match cli.command {
let mut res = match cli.command {
Some(cmd) => cmd.execute(&mut printer, cli.config_paths.as_ref()).await,
None => {
let config = TomlConfig::from_paths_or_default(cli.config_paths.as_ref()).await?;
@ -46,5 +53,15 @@ async fn main() -> Result<()> {
.execute(&mut printer, &config)
.await
}
}
};
if filter < LevelFilter::DEBUG {
res = res.note("Run with --debug to enable logs with spantrace.");
};
if filter < LevelFilter::TRACE {
res = res.note("Run with --trace to enable verbose logs with backtrace.")
};
res
}

View file

@ -1,9 +1,9 @@
use anyhow::Result;
use clap::{CommandFactory, Parser};
use clap_mangen::Man;
use log::info;
use color_eyre::Result;
use shellexpand_utils::{canonicalize, expand};
use std::{fs, path::PathBuf};
use tracing::info;
use crate::{cli::Cli, printer::Printer};

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use color_eyre::Result;
use dialoguer::Input;
use email::notmuch::config::NotmuchConfig;

View file

@ -1,5 +1,5 @@
use anyhow::{anyhow, Error, Result};
use clap::ValueEnum;
use color_eyre::{eyre::eyre, eyre::Error, Result};
use serde::Serialize;
use std::{
fmt,
@ -23,7 +23,7 @@ impl FromStr for OutputFmt {
match fmt {
fmt if fmt.eq_ignore_ascii_case("json") => Ok(Self::Json),
fmt if fmt.eq_ignore_ascii_case("plain") => Ok(Self::Plain),
unknown => Err(anyhow!("cannot parse output format {}", unknown)),
unknown => Err(eyre!("cannot parse output format {}", unknown)),
}
}
}
@ -69,7 +69,7 @@ impl FromStr for ColorFmt {
fmt if fmt.eq_ignore_ascii_case("always") => Ok(Self::Always),
fmt if fmt.eq_ignore_ascii_case("ansi") => Ok(Self::Ansi),
fmt if fmt.eq_ignore_ascii_case("auto") => Ok(Self::Auto),
unknown => Err(anyhow!("cannot parse color format {}", unknown)),
unknown => Err(eyre!("cannot parse color format {}", unknown)),
}
}
}

View file

@ -1,4 +1,4 @@
use anyhow::{Context, Result};
use color_eyre::{eyre::Context, Result};
use crate::printer::WriteColor;

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use color_eyre::Result;
use email::email::config::EmailTextPlainFormat;
use std::io;
use termcolor::{self, StandardStream};

View file

@ -1,5 +1,5 @@
use anyhow::{Context, Error, Result};
use clap::ArgMatches;
use color_eyre::{eyre::Context, Report, Result};
use std::fmt::{self, Debug};
use termcolor::StandardStream;
@ -87,7 +87,7 @@ impl From<OutputFmt> for StdoutPrinter {
}
impl TryFrom<&ArgMatches> for StdoutPrinter {
type Error = Error;
type Error = Report;
fn try_from(m: &ArgMatches) -> Result<Self, Self::Error> {
let fmt: OutputFmt = m

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use color_eyre::Result;
use dialoguer::Input;
use email::sendmail::config::SendmailConfig;

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use color_eyre::Result;
use dialoguer::{Confirm, Input, Password, Select};
#[cfg(feature = "account-discovery")]
use email::account::discover::config::{AuthenticationType, AutoConfig, SecurityType, ServerType};

40
src/tracing.rs Normal file
View file

@ -0,0 +1,40 @@
use color_eyre::eyre::Result;
use std::env;
use tracing_error::ErrorLayer;
use tracing_subscriber::{filter::LevelFilter, fmt, prelude::*, EnvFilter};
pub fn install() -> Result<LevelFilter> {
let fmt_layer = fmt::layer().with_target(false);
let (filter_layer, current_filter) = match EnvFilter::try_from_default_env() {
Err(_) => (EnvFilter::try_new("warn").unwrap(), LevelFilter::OFF),
Ok(layer) => {
let level = layer.max_level_hint().unwrap_or(LevelFilter::OFF);
(layer, level)
}
};
let registry = tracing_subscriber::registry()
.with(filter_layer)
.with(ErrorLayer::default());
if current_filter == LevelFilter::OFF {
registry.with(fmt_layer.without_time()).init()
} else {
registry.with(fmt_layer).init()
}
if env::var("RUST_BACKTRACE").is_err() && current_filter == LevelFilter::TRACE {
env::set_var("RUST_BACKTRACE", "1");
}
let debug = current_filter >= LevelFilter::DEBUG;
color_eyre::config::HookBuilder::new()
.capture_span_trace_by_default(debug)
.display_location_section(debug)
.display_env_section(false)
.install()?;
Ok(current_filter)
}

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use color_eyre::Result;
use dialoguer::Select;
use super::THEME;

View file

@ -1,4 +1,4 @@
use anyhow::{Context, Result};
use color_eyre::{eyre::Context, Result};
use email::{
account::config::AccountConfig,
email::utils::{local_draft_path, remove_local_draft},
@ -6,10 +6,10 @@ use email::{
folder::DRAFTS,
template::Template,
};
use log::debug;
use mml::MmlCompilerBuilder;
use process::SingleCommand;
use std::{env, fs, sync::Arc};
use tracing::debug;
use crate::{
backend::Backend,

View file

@ -4,11 +4,11 @@
//!
//! [builder design pattern]: https://refactoring.guru/design-patterns/builder
use anyhow::{Context, Result};
use color_eyre::{eyre::Context, Result};
use email::email::config::EmailTextPlainFormat;
use log::trace;
use termcolor::{Color, ColorSpec};
use terminal_size::terminal_size;
use tracing::trace;
use unicode_width::UnicodeWidthStr;
use crate::printer::{Print, PrintTableOpts, WriteColor};