refactor: Use miette error-diagnostic library
This commit is contained in:
parent
05b5efc8bf
commit
7e8f445967
3 changed files with 17 additions and 8 deletions
|
@ -6,8 +6,12 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bytes = "1.1"
|
bytes = "1.1"
|
||||||
|
|
||||||
|
miette = "4.7"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
|
tracing-futures = "0.2"
|
||||||
|
|
||||||
# IMAP
|
# IMAP
|
||||||
imap-codec = "0.5"
|
imap-codec = "0.5"
|
||||||
|
@ -16,11 +20,13 @@ imap-codec = "0.5"
|
||||||
async-compat = "0.2"
|
async-compat = "0.2"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
pin-project = "1.0"
|
pin-project = "1.0"
|
||||||
|
|
||||||
tokio = { version = "1.18", features = ["full"] }
|
tokio = { version = "1.18", features = ["full"] }
|
||||||
tokio-tower = "0.6"
|
tokio-tower = "0.6"
|
||||||
tower = { version = "0.4", features = ["full"] }
|
tower = { version = "0.4", features = ["full"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
eyre = "0.6"
|
miette = { version = "4.7", features = ["fancy"] }
|
||||||
|
|
||||||
tracing-subscriber = "0.3"
|
tracing-subscriber = "0.3"
|
||||||
console-subscriber = "0.1"
|
console-subscriber = "0.1"
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
use miette::{IntoDiagnostic, Result};
|
||||||
use boitalettres::proto::{Request, Response};
|
use boitalettres::proto::{Request, Response};
|
||||||
use boitalettres::server::accept::addr::{AddrIncoming, AddrStream};
|
use boitalettres::server::accept::addr::{AddrIncoming, AddrStream};
|
||||||
use boitalettres::server::Server;
|
use boitalettres::server::Server;
|
||||||
|
|
||||||
async fn handle_req(req: Request) -> eyre::Result<Response> {
|
async fn handle_req(req: Request) -> Result<Response> {
|
||||||
use imap_codec::types::response::Status;
|
use imap_codec::types::response::Status;
|
||||||
|
|
||||||
tracing::debug!("Got request: {:#?}", req);
|
tracing::debug!("Got request: {:#?}", req);
|
||||||
|
@ -13,10 +14,12 @@ async fn handle_req(req: Request) -> eyre::Result<Response> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> eyre::Result<()> {
|
async fn main() -> Result<()> {
|
||||||
setup_logging();
|
setup_logging();
|
||||||
|
|
||||||
let incoming = AddrIncoming::new("127.0.0.1:4567").await?;
|
let incoming = AddrIncoming::new("127.0.0.1:4567")
|
||||||
|
.await
|
||||||
|
.into_diagnostic()?;
|
||||||
|
|
||||||
let make_service = tower::service_fn(|addr: &AddrStream| {
|
let make_service = tower::service_fn(|addr: &AddrStream| {
|
||||||
tracing::debug!(remote_addr = %addr.remote_addr, local_addr = %addr.local_addr, "accept");
|
tracing::debug!(remote_addr = %addr.remote_addr, local_addr = %addr.local_addr, "accept");
|
||||||
|
@ -29,9 +32,8 @@ async fn main() -> eyre::Result<()> {
|
||||||
});
|
});
|
||||||
|
|
||||||
let server = Server::new(incoming).serve(make_service);
|
let server = Server::new(incoming).serve(make_service);
|
||||||
let _ = server.await?;
|
|
||||||
|
|
||||||
Ok(())
|
server.await.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't mind this, this is just for debugging.
|
// Don't mind this, this is just for debugging.
|
||||||
|
|
|
@ -15,8 +15,8 @@ mod conn;
|
||||||
mod pipeline;
|
mod pipeline;
|
||||||
mod service;
|
mod service;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
|
||||||
pub enum Error<A> {
|
pub enum Error<A: std::error::Error + 'static> {
|
||||||
#[error("Error occured when accepting new connections")]
|
#[error("Error occured when accepting new connections")]
|
||||||
Accept(#[source] A),
|
Accept(#[source] A),
|
||||||
#[error("Error occured on service creation")]
|
#[error("Error occured on service creation")]
|
||||||
|
@ -50,6 +50,7 @@ impl<I, S> Future for Server<I, S>
|
||||||
where
|
where
|
||||||
I: Accept,
|
I: Accept,
|
||||||
I::Conn: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
I::Conn: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
||||||
|
I::Error: 'static,
|
||||||
S: MakeServiceRef<I::Conn, Request, Response = Response>,
|
S: MakeServiceRef<I::Conn, Request, Response = Response>,
|
||||||
S::MakeError: Into<tower::BoxError> + std::fmt::Display,
|
S::MakeError: Into<tower::BoxError> + std::fmt::Display,
|
||||||
S::Error: std::fmt::Display,
|
S::Error: std::fmt::Display,
|
||||||
|
|
Loading…
Reference in a new issue