-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement some proper error handling
* implement error handling for Coordinates struct * complete rough error handling for config * update reasdme and bump version
- Loading branch information
Showing
12 changed files
with
388 additions
and
141 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "heliocron" | ||
version = "0.2.2" | ||
version = "0.3.0" | ||
authors = ["Michael Freeborn <[email protected]>"] | ||
description = """ | ||
Heliocron is a command line application written in Rust capable of delaying execution of other | ||
|
@@ -28,7 +28,6 @@ toml = "0.5" | |
[dev-dependencies] | ||
assert_cmd = "0.12" | ||
criterion = "0.3" | ||
guerrilla = "0.1" | ||
predicates = "1" | ||
|
||
[profile.release] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
use std::str::FromStr; | ||
use std::result; | ||
|
||
use super::errors::{ConfigErrorKind, HeliocronError}; | ||
|
||
type Result<T> = result::Result<T, HeliocronError>; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum Event { | ||
Sunrise, | ||
Sunset, | ||
} | ||
|
||
impl FromStr for Event { | ||
type Err = (); | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
let s: &str = &s.trim().to_lowercase(); | ||
|
||
match s { | ||
"sunrise" => Ok(Self::Sunrise), | ||
"sunset" => Ok(Self::Sunset), | ||
_ => Err(()), | ||
impl Event { | ||
pub fn new(event: &str) -> Result<Event> { | ||
let event = event.trim().to_lowercase(); | ||
match event.as_str() { | ||
"sunrise" => Ok(Event::Sunrise), | ||
"sunset" => Ok(Event::Sunset), | ||
_ => Err(HeliocronError::Config(ConfigErrorKind::InvalidEvent)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::error; | ||
|
||
use chrono; | ||
|
||
#[derive(Debug)] | ||
pub enum HeliocronError { | ||
Config(ConfigErrorKind), | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum ConfigErrorKind { | ||
InvalidCoordindates(&'static str), | ||
InvalidTomlFile, | ||
ParseDate, | ||
InvalidEvent, | ||
} | ||
|
||
impl ConfigErrorKind { | ||
fn as_str(&self) -> &str { | ||
match *self { | ||
ConfigErrorKind::InvalidCoordindates(msg) => msg, | ||
ConfigErrorKind::InvalidTomlFile => { | ||
"Error parsing .toml file. Ensure that it is of the correct format." | ||
} | ||
ConfigErrorKind::ParseDate => { | ||
"Error parsing date. Ensure the date and timezone formats are correct." | ||
} | ||
ConfigErrorKind::InvalidEvent => { | ||
"Error parsing event. Expected one of {'sunrise' | 'sunset'}" | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl std::fmt::Display for HeliocronError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match *self { | ||
HeliocronError::Config(ref err) => write!( | ||
f, | ||
"Config error: {}", | ||
match err { | ||
ConfigErrorKind::InvalidCoordindates(msg) => | ||
format!("Invalid coordinates - {}", msg), | ||
ConfigErrorKind::InvalidTomlFile => err.as_str().to_string(), | ||
ConfigErrorKind::ParseDate => err.as_str().to_string(), | ||
ConfigErrorKind::InvalidEvent => err.as_str().to_string(), | ||
} | ||
), | ||
} | ||
} | ||
} | ||
|
||
impl error::Error for HeliocronError { | ||
fn description(&self) -> &str { | ||
match *self { | ||
HeliocronError::Config(ref err) => err.as_str(), | ||
} | ||
} | ||
} | ||
|
||
impl From<chrono::ParseError> for HeliocronError { | ||
fn from(err: chrono::ParseError) -> Self { | ||
match err { | ||
_err => HeliocronError::Config(ConfigErrorKind::ParseDate), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod config; | ||
pub mod enums; | ||
pub mod errors; | ||
pub mod parsers; | ||
pub mod report; | ||
pub mod structs; | ||
|
Oops, something went wrong.