1use std::fmt;
2use std::io;
3use std::error;
4use {
5 Constant,
6 Call,
7 BuildError,
8};
9
10#[derive(Debug)]
12pub enum LittleError {
13 ParameterMissing(String),
15 ConstantMissing(Constant),
17 CallMissing(Call),
19 CallError(Box<error::Error + Sync + Send>),
21 OutputError(io::Error),
23 BuildError(BuildError),
25 StackUnderflow,
27 Interupt,
29}
30
31impl From<io::Error> for LittleError {
32 fn from(other: io::Error) -> LittleError {
33 LittleError::OutputError(other)
34 }
35}
36
37impl From<BuildError> for LittleError {
38 fn from(other: BuildError) -> LittleError {
39 LittleError::BuildError(other)
40 }
41}
42
43impl fmt::Display for LittleError {
44 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45 match *self {
46 LittleError::ParameterMissing(ref p) => write!(f, "Parameter {:?} is missing.", p),
47 LittleError::ConstantMissing(c) => write!(f, "Constant {:?} is missing.", c),
48 LittleError::CallMissing(c) => write!(f, "Call {:?} is missing.", c),
49 LittleError::CallError(ref e) => e.fmt(f),
50 LittleError::BuildError(ref e) => e.fmt(f),
51 LittleError::OutputError(ref e) => write!(f, "Output error: {:?}", e),
52 LittleError::StackUnderflow => write!(f, "Attempt to pop empty stack."),
53 LittleError::Interupt => write!(f, "Interupt."),
54 }
55 }
56}
57
58impl error::Error for LittleError {
59 fn description(&self) -> &str {
60 match *self {
61 LittleError::ParameterMissing(_) => "parameter is missing",
62 LittleError::ConstantMissing(_) => "constant is missing",
63 LittleError::CallMissing(_) => "call is missing",
64 LittleError::CallError(ref e) => e.description(),
65 LittleError::BuildError(ref e) => e.description(),
66 LittleError::OutputError(_) => "output error",
67 LittleError::StackUnderflow => "stack underflow",
68 LittleError::Interupt => "interupt",
69 }
70 }
71}
72
73pub type LittleResult<V> = Result<V, Box<error::Error>>;