From 465a71b6780921fb7ec19682702cbe864decd212 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Sun, 25 Feb 2024 16:54:03 +0100 Subject: Closes #3. Use thiserror. Fix clippy stuff --- src/error.rs | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs index 531528f..15e4308 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,21 +1,34 @@ use std::{fmt::Debug, num::ParseIntError}; -pub enum CliError { - Reqwest(reqwest::Error), - Config(config::ConfigError), - Serde(serde_json::Error), - Parse(ParseIntError), - WsResponse, -} +use reqwest::header::InvalidHeaderValue; -impl Debug for CliError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::Reqwest(err) => err.fmt(f), - Self::Config(err) => err.fmt(f), - Self::Serde(err) => err.fmt(f), - Self::Parse(err) => err.fmt(f), - Self::WsResponse => f.write_str("Error in Response"), - } - } +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("request: {source}")] + Reqwest { + #[from] + source: reqwest::Error, + }, + #[error("config: {source}")] + Config { + #[from] + source: config::ConfigError, + }, + #[error("serde: {source}")] + Serde { + #[from] + source: serde_json::Error, + }, + #[error("parse int: {source}")] + Parse { + #[from] + source: ParseIntError, + }, + #[error("parse header: {source}")] + InvalidHeaderValue { + #[from] + source: InvalidHeaderValue + }, + #[error("ws")] + WsResponse, } -- cgit v1.2.3