chiark / gitweb /
Make AuthError into a subcase of ClientError.
authorSimon Tatham <anakin@pobox.com>
Tue, 2 Jan 2024 11:35:06 +0000 (11:35 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 2 Jan 2024 17:30:18 +0000 (17:30 +0000)
Now tui.rs doesn't have to handle it directly, and our client setup
can return the more general ClientError.

src/auth.rs
src/client.rs
src/tui.rs

index ce195d9d13ba5a14d689785432b4e747b23de152..2983e1cd21819f4c2fd1548eb9adb9cceca3c5bb 100644 (file)
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
 
 use super::config::ConfigLocation;
 
-#[derive(Debug)]
+#[derive(Debug, PartialEq, Eq, Clone)]
 pub enum AuthError {
     Nonexistent(String),
     Bad(String),
index 66a32ef94521d9961b1cbf4aa859d77e668e9599..7c0df5b7b84081a5d2e52b4695b1434004024f2c 100644 (file)
@@ -60,11 +60,16 @@ pub struct Client {
 
 #[derive(Debug, PartialEq, Eq, Clone)]
 pub enum ClientError {
+    Auth(AuthError), // message
     InternalError(String), // message
     UrlParseError(String, String), // url, message
     UrlError(String, String), // url, message
 }
 
+impl From<AuthError> for ClientError {
+    fn from(err: AuthError) -> Self { ClientError::Auth(err) }
+}
+
 impl From<reqwest::Error> for ClientError {
     fn from(err: reqwest::Error) -> Self {
         match err.url() {
@@ -80,6 +85,8 @@ impl std::fmt::Display for ClientError {
         Result<(), std::fmt::Error>
     {
         match self {
+            ClientError::Auth(ref autherr) =>
+                write!(f, "unable to read authentication: {}", autherr),
             ClientError::InternalError(ref msg) =>
                 write!(f, "internal failure: {}", msg),
             ClientError::UrlParseError(ref url, ref msg) =>
@@ -152,7 +159,7 @@ pub enum FeedExtend {
 }
 
 impl Client {
-    pub fn new(cfgloc: &ConfigLocation) -> Result<Self, AuthError> {
+    pub fn new(cfgloc: &ConfigLocation) -> Result<Self, ClientError> {
         Ok(Client {
             auth: AuthConfig::load(cfgloc)?,
             client: reqwest::blocking::Client::new(),
index 70c55cc1d3d6930d035a7c0870c13d97ff1edb48..af0fa27451d524d35a4fe9402c2622ff8be36264 100644 (file)
@@ -22,7 +22,6 @@ use super::config::ConfigLocation;
 use super::menu::*;
 use super::file::*;
 use super::editor::*;
-use super::auth::AuthError;
 
 fn ratatui_style_from_colour(colour: char) -> Style {
     match colour {
@@ -171,13 +170,6 @@ impl From<std::io::Error> for TuiError {
         }
     }
 }
-impl From<AuthError> for TuiError {
-    fn from(err: AuthError) -> Self {
-        TuiError {
-            message: format!("unable to read authentication: {}", err),
-        }
-    }
-}
 impl From<ClientError> for TuiError {
     fn from(err: ClientError) -> Self {
         TuiError {