Bad(String),
}
+impl super::TopLevelErrorCandidate for AuthError {}
+
impl std::fmt::Display for AuthError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) ->
Result<(), std::fmt::Error>
UrlError(String, String), // url, message
}
+impl super::TopLevelErrorCandidate for ClientError {}
+
impl From<AuthError> for ClientError {
fn from(err: AuthError) -> Self { ClientError::Auth(err) }
}
Env(std::env::VarError),
}
+impl super::TopLevelErrorCandidate for ConfigError {}
+
impl std::fmt::Display for ConfigError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) ->
Result<(), std::fmt::Error>
pub mod file;
pub mod editor;
pub mod posting;
+
+#[derive(Debug)]
+pub struct TopLevelError {
+ prefix: String,
+ message: String,
+}
+
+impl TopLevelError {
+ fn new(prefix: &str, message: &str) -> Self {
+ TopLevelError {
+ prefix: prefix.to_owned(),
+ message: message.to_owned(),
+ }
+ }
+}
+
+impl std::fmt::Display for TopLevelError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) ->
+ Result<(), std::fmt::Error>
+ {
+ write!(f, "mastodonochrome: {}{}", self.prefix, self.message)
+ }
+}
+
+trait TopLevelErrorCandidate: std::fmt::Display {
+ fn get_prefix() -> String { "error: ".to_owned() }
+}
+
+impl<E: TopLevelErrorCandidate> From<E> for TopLevelError {
+ fn from(err: E) -> Self {
+ TopLevelError {
+ prefix: E::get_prefix(),
+ message: err.to_string(),
+ }
+ }
+}
+
+impl TopLevelErrorCandidate for clap::error::Error {
+ // clap prints its own "error: "
+ fn get_prefix() -> String { "".to_owned() }
+}
+
+impl TopLevelErrorCandidate for std::io::Error {}
use clap::Parser;
-use std::fmt::Display;
use std::process::ExitCode;
-use mastodonochrome::client::ClientError;
-use mastodonochrome::config::{ConfigLocation, ConfigError};
-use mastodonochrome::tui::{Tui, TuiError};
+use mastodonochrome::TopLevelError;
+use mastodonochrome::config::ConfigLocation;
+use mastodonochrome::tui::Tui;
use mastodonochrome::login::login;
#[derive(Parser, Debug)]
login: Option<String>,
}
-#[derive(Debug)]
-pub struct TopLevelError {
- prefix: String,
- message: String,
-}
-
-impl Display for TopLevelError {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) ->
- Result<(), std::fmt::Error>
- {
- write!(f, "mastodonochrome: {}{}", self.prefix, self.message)
- }
-}
-
-trait TopLevelErrorCandidate: Display {
- fn get_prefix() -> String { "error: ".to_owned() }
-}
-
-impl<E: TopLevelErrorCandidate> From<E> for TopLevelError {
- fn from(err: E) -> Self {
- TopLevelError {
- prefix: E::get_prefix(),
- message: err.to_string(),
- }
- }
-}
-
-impl TopLevelErrorCandidate for ConfigError {}
-impl TopLevelErrorCandidate for TuiError {}
-impl TopLevelErrorCandidate for ClientError {}
-impl TopLevelErrorCandidate for clap::error::Error {
- // clap prints its own "error: "
- fn get_prefix() -> String { "".to_owned() }
-}
-
fn main_inner() -> Result<(), TopLevelError> {
let cli = Args::try_parse()?;
let cfgloc = match cli.config {
}
}
+impl super::TopLevelErrorCandidate for TuiError {}
+
impl From<std::io::Error> for TuiError {
fn from(err: std::io::Error) -> Self {
TuiError {