forked from clog-tool/clog-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: implementing clog-tool#58 and better errors
- Loading branch information
Showing
3 changed files
with
148 additions
and
44 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::error::Error as StdError; | ||
use std::fmt; | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
ConfigParseErr(String), | ||
ConfigFormatErr(String), | ||
CurrentDirErr(StdError), | ||
TomlReadErr(StdError), | ||
|
||
} | ||
|
||
|
||
// Shamelessly taken and adopted from https://github.com/BurntSushi :) | ||
impl Error { | ||
/// Return whether this was a fatal error or not. | ||
pub fn fatal(&self) -> bool { | ||
match *self { | ||
|
||
} | ||
} | ||
|
||
/// Print this error and immediately exit the program. | ||
/// | ||
/// If the error is non-fatal then the error is printed to stdout and the | ||
/// exit status will be `0`. Otherwise, when the error is fatal, the error | ||
/// is printed to stderr and the exit status will be `1`. | ||
pub fn exit(&self) -> ! { | ||
if self.fatal() { | ||
wlnerr!("{}\n", self); | ||
::std::process::exit(1) | ||
} else { | ||
println!("{}", self); | ||
::std::process::exit(0) | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match *self { | ||
|
||
} | ||
} | ||
} | ||
|
||
impl StdError for Error { | ||
fn description(&self) -> &str { | ||
match *self { | ||
|
||
} | ||
} | ||
|
||
fn cause(&self) -> Option<&StdError> { | ||
match *self { | ||
|
||
} | ||
} | ||
} |