diff --git a/src/error.rs b/src/error.rs deleted file mode 100644 index 4a1b0b31..00000000 --- a/src/error.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::fmt; - -use reqwest::Error as ReqwestError; - -#[derive(Debug)] -#[allow(clippy::enum_variant_names)] -pub enum TealdeerError { - UpdateError(String), -} - -impl From for TealdeerError { - fn from(err: ReqwestError) -> Self { - Self::UpdateError(format!("HTTP error: {}", err.to_string())) - } -} - -impl fmt::Display for TealdeerError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - Self::UpdateError(e) => write!(f, "UpdateError: {}", e), - } - } -} diff --git a/src/formatter.rs b/src/formatter.rs index 97899751..c87d39b6 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -1,9 +1,9 @@ //! Functions related to formatting and printing lines from a `Tokenizer`. -use crate::{extensions::FindFrom, types::LineType}; - use log::debug; +use crate::{extensions::FindFrom, types::LineType}; + #[derive(Debug, Clone, Copy, PartialEq, Eq)] /// Represents a snippet from a page of a specific highlighting class. pub enum PageSnippet<'a> { diff --git a/src/main.rs b/src/main.rs index 25f31e44..a7d376db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,6 @@ use pager::Pager; mod cache; mod config; -mod error; pub mod extensions; mod formatter; mod line_iterator; @@ -303,7 +302,7 @@ fn create_config_and_exit(enable_styles: bool) { process::exit(0); } Err(e) => { - print_error(enable_styles, &e); + print_error(enable_styles, &e.context("Could not create seed config")); process::exit(1); } } diff --git a/src/types.rs b/src/types.rs index 39817763..f80aa980 100644 --- a/src/types.rs +++ b/src/types.rs @@ -2,6 +2,7 @@ use std::{fmt, str}; +use anyhow::{anyhow, Result}; use serde_derive::{Deserialize, Serialize}; #[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize, Deserialize)] @@ -26,7 +27,7 @@ impl fmt::Display for PlatformType { } impl str::FromStr for PlatformType { - type Err = String; + type Err = anyhow::Error; fn from_str(s: &str) -> Result { match s { @@ -34,7 +35,7 @@ impl str::FromStr for PlatformType { "osx" | "macos" => Ok(Self::OsX), "sunos" => Ok(Self::SunOs), "windows" => Ok(Self::Windows), - other => Err(format!( + other => Err(anyhow!( "Unknown OS: {}. Possible values: linux, macos, osx, sunos, windows", other )), @@ -87,14 +88,14 @@ pub enum ColorOptions { } impl str::FromStr for ColorOptions { - type Err = String; + type Err = anyhow::Error; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { match s { "always" => Ok(Self::Always), "auto" => Ok(Self::Auto), "never" => Ok(Self::Never), - other => Err(format!( + other => Err(anyhow!( "Unknown color option: {}. Possible values: always, auto, never", other )),