summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaz <ndpm13@ch-naseem.com>2025-07-31 14:54:01 +0100
committerNaz <ndpm13@ch-naseem.com>2025-07-31 14:54:01 +0100
commitbd230c3d916be2af8f97e587f3f764800077cba4 (patch)
tree44352a4fe4c475472da2dddc9e9b0403a63d5bb1
parent61b6008db55f8aa6d9cc8d8998c3e28916e144cc (diff)
✨feat: implement Display and Error traits for custom Error enum
-rw-r--r--src/error.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index 0183e38..3c51529 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -19,3 +19,21 @@ pub enum Error {
#[from]
EnvVar(std::env::VarError),
}
+
+impl core::fmt::Display for Error {
+ fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::result::Result<(), std::fmt::Error> {
+ match self {
+ Error::Io(e) => match e.kind() {
+ std::io::ErrorKind::NotFound => write!(fmt, "File or directory not found"),
+ _ => write!(fmt, "IO error: {e}"),
+ },
+ Error::NotFound(name) => write!(fmt, "Application '{name}' not found"),
+ Error::Json(e) => write!(fmt, "JSON error: {e}"),
+ Error::Http(e) => write!(fmt, "HTTP error: {e}"),
+ Error::EnvVar(e) => write!(fmt, "Environment variable error: {e}"),
+ Error::InvalidPath => write!(fmt, "Invalid path provided"),
+ }
+ }
+}
+
+impl std::error::Error for Error {}