about summary refs log tree commit diff stats
path: root/pkgs/by-name/ba/back/src/error/mod.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-03-08 21:50:22 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-03-09 13:44:42 +0100
commita9ff6e1c86ad51b3fa568ea7caa992df5db8c316 (patch)
tree65cb6404fce4f84be9ed6561ed152d0d21e3b875 /pkgs/by-name/ba/back/src/error/mod.rs
parentscripts/get_dns.sh: Init (diff)
downloadnixos-server-a9ff6e1c86ad51b3fa568ea7caa992df5db8c316.zip
pkgs/back: Support listing all repos via the `/` path
This change required porting all webhandling from rocket to hyper,
because we needed fine grained control over the path the user
requested. This should also improve the memory and resources footprint
because hyper is more lower level.

I also changed all of the templates from `format!()` calls to a real
templating language because I needed to touch most code paths anyway.
Diffstat (limited to 'pkgs/by-name/ba/back/src/error/mod.rs')
-rw-r--r--pkgs/by-name/ba/back/src/error/mod.rs66
1 files changed, 53 insertions, 13 deletions
diff --git a/pkgs/by-name/ba/back/src/error/mod.rs b/pkgs/by-name/ba/back/src/error/mod.rs
index 8b71700..8889033 100644
--- a/pkgs/by-name/ba/back/src/error/mod.rs
+++ b/pkgs/by-name/ba/back/src/error/mod.rs
@@ -9,37 +9,53 @@
 // You should have received a copy of the License along with this program.
 // If not, see <https://www.gnu.org/licenses/agpl.txt>.
 
-use std::{fmt::Display, io, path::PathBuf};
+use std::{fmt::Display, io, net::SocketAddr, path::PathBuf};
 
+use gix::hash::Prefix;
 use thiserror::Error;
 
-use crate::web::prefix::BackPrefix;
-
 pub type Result<T> = std::result::Result<T, Error>;
 
-pub mod responder;
-
 #[derive(Error, Debug)]
 pub enum Error {
     ConfigParse {
         file: PathBuf,
         error: serde_json::Error,
     },
+
+    ProjectListRead {
+        file: PathBuf,
+        error: io::Error,
+    },
     ConfigRead {
         file: PathBuf,
         error: io::Error,
     },
-    RocketLaunch(#[from] rocket::Error),
-
+    NotGitBug {
+        path: PathBuf,
+    },
     RepoOpen {
         repository_path: PathBuf,
         error: Box<gix::open::Error>,
     },
+    RepoFind {
+        repository_path: PathBuf,
+    },
     RepoRefsIter(#[from] gix::refs::packed::buffer::open::Error),
-    RepoRefsPrefixed(#[from] std::io::Error),
+    RepoRefsPrefixed {
+        error: io::Error,
+    },
+
+    TcpBind {
+        addr: SocketAddr,
+        err: io::Error,
+    },
+    TcpAccept {
+        err: io::Error,
+    },
 
     IssuesPrefixMissing {
-        prefix: BackPrefix,
+        prefix: Prefix,
     },
     IssuesPrefixParse(#[from] gix::hash::prefix::from_hex::Error),
 }
@@ -54,6 +70,13 @@ impl Display for Error {
                     file.display()
                 )
             }
+            Error::ProjectListRead { file, error } => {
+                write!(
+                    f,
+                    "while trying to read the project.list file ({}): {error}",
+                    file.display()
+                )
+            }
             Error::ConfigRead { file, error } => {
                 write!(
                     f,
@@ -61,9 +84,6 @@ impl Display for Error {
                     file.display()
                 )
             }
-            Error::RocketLaunch(error) => {
-                write!(f, "while trying to start back: {error}")
-            }
             Error::RepoOpen {
                 repository_path,
                 error,
@@ -74,10 +94,24 @@ impl Display for Error {
                     repository_path.display()
                 )
             }
+            Error::NotGitBug { path } => {
+                write!(
+                    f,
+                    "Repository ('{}') has no initialized git-bug data",
+                    path.display()
+                )
+            }
+            Error::RepoFind { repository_path } => {
+                write!(
+                    f,
+                    "failed to find the repository at path: '{}'",
+                    repository_path.display()
+                )
+            }
             Error::RepoRefsIter(error) => {
                 write!(f, "while iteration over the refs in a repository: {error}",)
             }
-            Error::RepoRefsPrefixed(error) => {
+            Error::RepoRefsPrefixed { error, .. } => {
                 write!(f, "while prefixing the refs with a path: {error}")
             }
             Error::IssuesPrefixMissing { prefix } => {
@@ -89,6 +123,12 @@ impl Display for Error {
             Error::IssuesPrefixParse(error) => {
                 write!(f, "The given prefix can not be parsed as prefix: {error}")
             }
+            Error::TcpBind { addr, err } => {
+                write!(f, "while trying to open tcp {addr} for listening: {err}.")
+            }
+            Error::TcpAccept { err } => {
+                write!(f, "while trying to accept a tcp connection: {err}.")
+            }
         }
     }
 }