Improved error handling (part 3)

This commit is contained in:
mdecimus
2024-07-17 18:33:22 +02:00
parent e74b29189a
commit d2ad44cf9f
166 changed files with 2806 additions and 2692 deletions

View File

@@ -10,7 +10,7 @@ use directory::{
lookup::DirectoryStore, manage::ManageDirectory, PrincipalField, PrincipalUpdate,
PrincipalValue,
},
DirectoryError, ManagementError, Principal, QueryBy, Type,
Principal, QueryBy, Type,
};
use jmap_proto::types::collection::Collection;
use mail_send::Credentials;

View File

@@ -5,7 +5,7 @@
*/
pub mod imap;
pub mod internal;
//pub mod internal;
pub mod ldap;
pub mod smtp;
pub mod sql;
@@ -392,6 +392,8 @@ pub fn dummy_tls_acceptor() -> Arc<TlsAcceptor> {
let cert_file = &mut BufReader::new(CERT.as_bytes());
let key_file = &mut BufReader::new(PK.as_bytes());
let todo = "fix interkal";
// convert files to key/cert objects
let cert_chain = certs(cert_file).map(|r| r.unwrap()).collect();
let mut keys: Vec<PrivateKeyDer> = pkcs8_private_keys(key_file)

View File

@@ -7,7 +7,7 @@
use std::sync::Arc;
use common::listener::limiter::{ConcurrencyLimiter, InFlight};
use directory::{DirectoryError, QueryBy};
use directory::QueryBy;
use mail_parser::decoders::base64::base64_decode;
use mail_send::Credentials;
use tokio::{
@@ -87,13 +87,23 @@ async fn lmtp_directory() {
.into(),
Item::Verify(v) => match core.vrfy(&handle, v).await {
Ok(v) => v.into(),
Err(DirectoryError::Unsupported) => LookupResult::False,
Err(e) => panic!("Unexpected error: {e:?}"),
Err(e) => {
if e.matches(trc::StoreCause::NotSupported) {
LookupResult::False
} else {
panic!("Unexpected error: {e:?}")
}
}
},
Item::Expand(v) => match core.expn(&handle, v).await {
Ok(v) => v.into(),
Err(DirectoryError::Unsupported) => LookupResult::False,
Err(e) => panic!("Unexpected error: {e:?}"),
Err(e) => {
if e.matches(trc::StoreCause::NotSupported) {
LookupResult::False
} else {
panic!("Unexpected error: {e:?}")
}
}
},
};
@@ -121,13 +131,23 @@ async fn lmtp_directory() {
.into(),
Item::Verify(v) => match core.vrfy(&handle, v).await {
Ok(v) => v.into(),
Err(DirectoryError::Unsupported) => LookupResult::False,
Err(e) => panic!("Unexpected error: {e:?}"),
Err(e) => {
if e.matches(trc::StoreCause::NotSupported) {
LookupResult::False
} else {
panic!("Unexpected error: {e:?}")
}
}
},
Item::Expand(v) => match core.expn(&handle, v).await {
Ok(v) => v.into(),
Err(DirectoryError::Unsupported) => LookupResult::False,
Err(e) => panic!("Unexpected error: {e:?}"),
Err(e) => {
if e.matches(trc::StoreCause::NotSupported) {
LookupResult::False
} else {
panic!("Unexpected error: {e:?}")
}
}
},
};

View File

@@ -10,10 +10,7 @@ use crate::{
jmap::{assert_is_empty, mailbox::destroy_all_mailboxes},
store::deflate_test_resource,
};
use jmap::{
email::ingest::{IngestEmail, IngestSource},
IngestError,
};
use jmap::email::ingest::{IngestEmail, IngestSource};
use jmap_client::{email, mailbox::Role};
use jmap_proto::types::{collection::Collection, id::Id};
use mail_parser::{mailbox::mbox::MessageIterator, MessageParser};
@@ -256,21 +253,16 @@ async fn test_multi_thread(params: &mut JMAPTest) {
.await
{
Ok(_) => break,
Err(IngestError::Temporary) if retry_count < 10 => {
//println!("Retrying ingest for {}...", message.from());
let backoff = rand::thread_rng().gen_range(50..=300);
tokio::time::sleep(Duration::from_millis(backoff)).await;
retry_count += 1;
continue;
Err(err) => {
if err.is_assertion_failure() && retry_count < 10 {
//println!("Retrying ingest for {}...", message.from());
let backoff = rand::thread_rng().gen_range(50..=300);
tokio::time::sleep(Duration::from_millis(backoff)).await;
retry_count += 1;
continue;
}
panic!("Failed to ingest message: {:?}", err);
}
Err(IngestError::Permanent { .. }) => {
panic!(
"Failed to ingest message: {:?} {}",
message.from(),
String::from_utf8_lossy(message.contents())
);
}
Err(err) => panic!("Failed to ingest message: {:?}", err),
}
}
}));

View File

@@ -140,7 +140,7 @@ pub fn spawn_mock_webhook_endpoint() -> Arc<MockWebhookEndpoint> {
//let c = print!("rejected webhook: {}", serde_json::to_string_pretty(&request).unwrap());
Ok::<_, hyper::Error>(
RequestError::not_found().into_http_response()
Err(trc::ResourceCause::NotFound.into_err())
)
}