1use std::error::Error;
4use std::fmt;
5use std::io;
6use std::result;
7
8#[derive(Debug)]
10pub enum GitGlobalError {
11 BadSubcommand(String),
12 Generic,
13}
14
15pub type Result<T> = result::Result<T, GitGlobalError>;
17
18impl fmt::Display for GitGlobalError {
19 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20 use GitGlobalError::*;
21 match *self {
22 BadSubcommand(ref cmd) => {
23 write!(f, "Unknown subcommand \"{}\".", cmd)
24 }
25 Generic => write!(f, "An error occured :(."),
26 }
27 }
28}
29
30impl Error for GitGlobalError {
31 fn description(&self) -> &str {
32 use GitGlobalError::*;
33 match *self {
34 BadSubcommand(_) => "unknown subcommand",
35 Generic => "an error occurred :(",
36 }
37 }
38}
39
40impl From<io::Error> for GitGlobalError {
41 #[allow(unused_variables)]
42 fn from(err: io::Error) -> GitGlobalError {
43 GitGlobalError::Generic
44 }
45}