From db31e770be89cc3e693ffef470878267efeff406 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Mon, 28 Dec 2020 16:29:24 -0800 Subject: the which builtin now sorta works. yay! --- src/error.rs | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'src/error.rs') 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 for Error { fn from(e: std::io::Error) -> Error { Error::IO(e) @@ -53,3 +70,14 @@ impl From> for Error { } } +impl From for Error { + fn from(e: FileNameError) -> Error { + Error::FileName(e) + } +} + +impl From for Error { + fn from(e: DirectoryNameError) -> Error { + Error::DirectoryName(e) + } +} -- cgit 1.4.1