diff options
author | Irene Knapp <ireneista@gmail.com> | 2020-12-25 21:10:37 -0800 |
---|---|---|
committer | Irene Knapp <ireneista@gmail.com> | 2020-12-25 21:10:37 -0800 |
commit | efc68f54e3476de0bd209995c36043c26131b8df (patch) | |
tree | 676d6915d9daa336586aeb50fb46dcaf09622efb /src/error.rs | |
parent | f5ec40b8fbbe7d4409d94dafcbfcdd41b8a6202b (diff) |
refactor path parsing into a separate file, implement some Display traits, etc
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/error.rs b/src/error.rs index 96be297..6fe18db 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,3 +1,6 @@ +use crate::path::GenericPath; + + type ParseError<'a> = lalrpop_util::ParseError<usize, lalrpop_util::lexer::Token<'a>, &'a str>; @@ -5,6 +8,10 @@ type ParseError<'a> = pub enum Error { IO(std::io::Error), Parse(String), + PathListHasEmptyComponents(String), + PathIsAFile(String), + PathIsRelative(GenericPath), + PathInvalid(GenericPath), } impl std::error::Error for Error { } @@ -14,18 +21,22 @@ impl std::fmt::Display for Error { match self { Error::IO(e) => e.fmt(f), Error::Parse(e) => e.fmt(f), - } - } -} - -impl std::cmp::PartialEq for Error { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (Error::IO(_), Error::IO(_)) => - false, - (Error::Parse(_), Error::Parse(_)) => - false, - _ => false, + Error::PathListHasEmptyComponents(path_list) => + f.write_fmt(format_args!( + "Path list has empty components: {}", + path_list)), + Error::PathIsAFile(path) => + f.write_fmt(format_args!( + "There's a file at {}, not a directory.", + path)), + Error::PathIsRelative(path) => + f.write_fmt(format_args!( + "The path {} is relative, not absolute.", + path)), + Error::PathInvalid(path) => + f.write_fmt(format_args!( + "This isn't a valid path. {}", + path)), } } } |