improve envelope list query error diagnostics

This commit is contained in:
Clément DOUIN 2024-02-29 10:21:01 +01:00
parent 1e7adc5e0c
commit 46bf3eebfc
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
4 changed files with 36 additions and 26 deletions

View file

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Fixed watch IMAP envelopes when folder was empty [#179].
### Changed
- Changed the `envelope list` options:

5
Cargo.lock generated
View file

@ -635,8 +635,7 @@ dependencies = [
[[package]]
name = "chumsky"
version = "1.0.0-alpha.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9c28d4e5dd9a9262a38b231153591da6ce1471b818233f4727985d3dd0ed93c"
source = "git+https://github.com/zesterer/chumsky.git?rev=6837537#68375371a5fde6ee14f190c14e9a9cee0697f022"
dependencies = [
"hashbrown",
"regex-automata 0.3.9",
@ -1219,7 +1218,7 @@ dependencies = [
[[package]]
name = "email-lib"
version = "0.22.3"
source = "git+https://git.sr.ht/~soywod/pimalaya#79af9b0fa5fb30dcb1f8fbd322f7e40b9e05053a"
source = "git+https://git.sr.ht/~soywod/pimalaya#17838306e588fd1382da4b49ec1ed9ff846f33f0"
dependencies = [
"advisory-lock",
"anyhow",

View file

@ -92,3 +92,4 @@ version = "0.1"
[patch.crates-io]
email-lib = { git = "https://git.sr.ht/~soywod/pimalaya" }
chumsky = { git = "https://github.com/zesterer/chumsky.git", rev = "6837537" }

View file

@ -1,8 +1,12 @@
use anyhow::Result;
use ariadne::{Color, Label, Report, ReportKind, Source};
use clap::Parser;
use email::{backend::feature::BackendFeatureSource, envelope::list::ListEnvelopesOptions};
use email::{
backend::feature::BackendFeatureSource, envelope::list::ListEnvelopesOptions,
search_query::SearchEmailsQuery,
};
use log::info;
use std::process::exit;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;
@ -95,35 +99,37 @@ impl ListEnvelopesCommand {
)
.await?;
let filter = match self.query.map(|filter| filter.join(" ").parse()) {
Some(Ok(filter)) => Some(filter),
Some(Err(err)) => {
if let email::envelope::list::Error::ParseFilterError(errs, query) = &err {
errs.into_iter().for_each(|e| {
Report::build(ReportKind::Error, "query", e.span().start)
.with_message(e.to_string())
.with_label(
Label::new(("query", e.span().into_range()))
.with_message(e.reason().to_string())
.with_color(Color::Red),
)
.finish()
.eprint(("query", Source::from(&query)))
.unwrap()
});
};
let query = self
.query
.map(|query| query.join(" ").parse::<SearchEmailsQuery>());
Err(err)?;
None
}
let query = match query {
None => None,
Some(Ok(query)) => Some(query),
Some(Err(main_err)) => {
let source = "query";
let email::search_query::Error::ParseError(errs, query) = &main_err;
for err in errs {
Report::build(ReportKind::Error, source, err.span().start)
.with_message(main_err.to_string())
.with_label(
Label::new((source, err.span().into_range()))
.with_message(err.reason().to_string())
.with_color(Color::Red),
)
.finish()
.eprint((source, Source::from(&query)))
.unwrap();
}
exit(0)
}
};
let opts = ListEnvelopesOptions {
page,
page_size,
filter,
sort: Default::default(),
query,
};
let envelopes = backend.list_envelopes(folder, opts).await?;