Skip to content

Commit

Permalink
Add special status for directories
Browse files Browse the repository at this point in the history
  • Loading branch information
mattias-p committed Mar 15, 2018
1 parent c5559a9 commit 6f6bf8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum ErrorKind {
NoFragment,
Protocol,
Absolute,
Directory,
InvalidUrl,
NoMime,
UnrecognizedMime,
Expand Down Expand Up @@ -49,6 +50,7 @@ impl fmt::Display for ErrorKind {
ErrorKind::NoFragment => write!(f, "NO_FRAG"),
ErrorKind::Protocol => write!(f, "PROTOCOL"),
ErrorKind::Absolute => write!(f, "ABSOLUTE"),
ErrorKind::Directory => write!(f, "DIR"),
ErrorKind::NoMime => write!(f, "NO_MIME"),
ErrorKind::UnrecognizedMime => write!(f, "MIME"),
ErrorKind::DecodingError => write!(f, "DEC_ERR"),
Expand Down Expand Up @@ -77,6 +79,7 @@ impl FromStr for ErrorKind {
"NO_FRAG" => Ok(ErrorKind::NoFragment),
"PROTOCOL" => Ok(ErrorKind::Protocol),
"ABSOLUTE" => Ok(ErrorKind::Absolute),
"DIR" => Ok(ErrorKind::Directory),
"NO_MIME" => Ok(ErrorKind::NoMime),
"MIME" => Ok(ErrorKind::UnrecognizedMime),
"PREFIXED" => Ok(ErrorKind::Prefixed),
Expand Down Expand Up @@ -139,6 +142,7 @@ impl fmt::Display for LookupError {
ErrorKind::NoFragment => write!(f, "Fragment not found"),
ErrorKind::Protocol => write!(f, "Unhandled protocol"),
ErrorKind::Absolute => write!(f, "Unable to handle absolute path"),
ErrorKind::Directory => write!(f, "Document is a directory"),
ErrorKind::NoMime => write!(f, "No mime type"),
ErrorKind::UnrecognizedMime => write!(f, "Unrecognized mime type"),
ErrorKind::DecodingError => write!(f, "Decoding error"),
Expand All @@ -158,6 +162,7 @@ impl error::Error for LookupError {
ErrorKind::NoFragment => "fragment not found",
ErrorKind::Protocol => "unrecognized protocol",
ErrorKind::Absolute => "unhandled absolute path",
ErrorKind::Directory => "document is a directory",
ErrorKind::NoMime => "no mime type",
ErrorKind::UnrecognizedMime => "unrecognized mime type",
ErrorKind::DecodingError => "decoding error",
Expand Down
11 changes: 6 additions & 5 deletions src/linky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,13 @@ struct FilesystemLocalResolver;
impl LocalResolver for FilesystemLocalResolver {
fn local(&self, path: &Path) -> Result<Document, LookupError> {
if path.is_absolute() {
return Err(ErrorKind::Absolute.into());
Err(ErrorKind::Absolute.into())
} else if path.is_dir() {
Err(ErrorKind::Directory.into())
} else {
let reader = File::open(&path)?;
Document::parse(reader, &MARKDOWN_CONTENT_TYPE)
}

let reader = File::open(&path)?;

Document::parse(reader, &MARKDOWN_CONTENT_TYPE)
}
}

Expand Down

0 comments on commit 6f6bf8e

Please sign in to comment.