mirror of
https://github.com/figsoda/mmtc
synced 2024-11-22 15:13:03 +00:00
improve error messages
This commit is contained in:
parent
a155feb233
commit
15d1ec67a8
2 changed files with 10 additions and 11 deletions
|
@ -5,7 +5,7 @@ use serde::{
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
cmp::min,
|
cmp::min,
|
||||||
error,
|
error::Error as StdError,
|
||||||
fmt::{self, Formatter},
|
fmt::{self, Formatter},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ impl<'de> Deserialize<'de> for Texts {
|
||||||
formatter.write_str("enum Texts")
|
formatter.write_str("enum Texts")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_unit<E: error::Error>(self) -> Result<Self::Value, E> {
|
fn visit_unit<E: StdError>(self) -> Result<Self::Value, E> {
|
||||||
Ok(Texts::Empty)
|
Ok(Texts::Empty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -7,7 +7,7 @@ mod fail;
|
||||||
mod layout;
|
mod layout;
|
||||||
mod mpd;
|
mod mpd;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Error, Result};
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEvent},
|
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEvent},
|
||||||
execute,
|
execute,
|
||||||
|
@ -20,7 +20,6 @@ use tokio::{
|
||||||
use tui::{backend::CrosstermBackend, Terminal};
|
use tui::{backend::CrosstermBackend, Terminal};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Display,
|
|
||||||
io::{stdout, Write},
|
io::{stdout, Write},
|
||||||
net::{IpAddr, Ipv4Addr, SocketAddr},
|
net::{IpAddr, Ipv4Addr, SocketAddr},
|
||||||
process::exit,
|
process::exit,
|
||||||
|
@ -38,11 +37,8 @@ fn cleanup() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn die<T>(e: impl Display) -> T {
|
fn die<T>(e: impl Into<Error>) -> T {
|
||||||
if let Err(e) = cleanup() {
|
eprintln!("{:?}", cleanup().map_or_else(|x| x, |_| e.into()));
|
||||||
eprintln!("{}", e);
|
|
||||||
};
|
|
||||||
eprintln!("{}", e);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,9 +51,12 @@ enum Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() {
|
||||||
let res = run().await;
|
let res = run().await;
|
||||||
cleanup().and_then(|_| res).map_or_else(Err, |_| exit(0))
|
if let Err(e) = cleanup().and_then(|_| res) {
|
||||||
|
eprintln!("{:?}", e);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run() -> Result<()> {
|
async fn run() -> Result<()> {
|
||||||
|
|
Loading…
Reference in a new issue