summary refs log tree commit diff
path: root/src/error.rs
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@gmail.com>2020-12-28 16:29:24 -0800
committerIrene Knapp <ireneista@gmail.com>2020-12-28 16:29:24 -0800
commitdb31e770be89cc3e693ffef470878267efeff406 (patch)
treef09c7dab9d2b9db0a09650d071b6577e001e5b98 /src/error.rs
parentbcd2e282af2b6cd7991d8d1c5ebef4e4e4a1c745 (diff)
the which builtin now sorta works. yay!
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/error.rs b/src/error.rs
index 8e51880..018d812 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,4 +1,5 @@
 use crate::path::GenericPath;
+use crate::path::error::{FileNameError, DirectoryNameError};
 
 
 type ParseError<'a> =
@@ -8,10 +9,13 @@ type ParseError<'a> =
 pub enum Error {
   IO(std::io::Error),
   Parse(String),
+  FileName(FileNameError),
+  DirectoryName(DirectoryNameError),
   PathListHasEmptyComponents(String),
-  PathIsAFile(GenericPath),
-  PathIsRelative(GenericPath),
-  PathInvalid(GenericPath),
+  PathLexicallyDirectory(GenericPath),
+  PathLexicallyRelative(GenericPath),
+  PathLexicallyInvalid(GenericPath),
+  PathEmpiricallyFile(GenericPath),
 }
 
 impl std::error::Error for Error { }
@@ -21,26 +25,39 @@ impl std::fmt::Display for Error {
     match self {
       Error::IO(e) => e.fmt(f),
       Error::Parse(e) => e.fmt(f),
+      Error::FileName(e) => e.fmt(f),
+      Error::DirectoryName(e) => e.fmt(f),
       Error::PathListHasEmptyComponents(path_list) =>
         f.write_fmt(format_args!(
             "Path list has empty components: {}",
             path_list)),
-      Error::PathIsAFile(path) =>
+      Error::PathLexicallyDirectory(path) =>
         f.write_fmt(format_args!(
-            "There's a file at {}, not a directory.",
+            "The path {} ends in a slash, but is supposed to refer to a file, \
+             not a directory.",
             path)),
-      Error::PathIsRelative(path) =>
+      Error::PathLexicallyRelative(path) =>
         f.write_fmt(format_args!(
             "The path {} is relative, not absolute.",
             path)),
-      Error::PathInvalid(path) =>
+      Error::PathLexicallyInvalid(path) =>
         f.write_fmt(format_args!(
             "This isn't a valid path. {}",
             path)),
+      Error::PathEmpiricallyFile(path) =>
+        f.write_fmt(format_args!(
+            "There's a file at {}, not a directory.",
+            path)),
     }
   }
 }
 
+impl From<()> for Error {
+  fn from(_: ()) -> Error {
+    unreachable!()
+  }
+}
+
 impl From<std::io::Error> for Error {
   fn from(e: std::io::Error) -> Error {
     Error::IO(e)
@@ -53,3 +70,14 @@ impl From<ParseError<'_>> for Error {
   }
 }
 
+impl From<FileNameError> for Error {
+  fn from(e: FileNameError) -> Error {
+    Error::FileName(e)
+  }
+}
+
+impl From<DirectoryNameError> for Error {
+  fn from(e: DirectoryNameError) -> Error {
+    Error::DirectoryName(e)
+  }
+}