use std::fmt;
use std::io;
use std::error::Error;
use Pos;
quick_error! {
#[derive(Debug)]
pub enum DataError {
AttrUnsupported(typename: &'static str) {
description("object doesn't support getting attribute `a.b`")
display("object {} doesn't support getting attribute", typename)
}
AttrNotFound {
description("object doesn't have such attibute")
}
IndexUnsupported(typename: &'static str) {
description("object doesn't support subscription `a[b]`")
display("object {} doesn't support subscription", typename)
}
StrKeyUnsupported(typename: &'static str) {
description("can't be stringified for subsciption `a[b]`")
display("object {} can't be stringified to be used as key", typename)
}
IntKeyUnsupported(typename: &'static str) {
description("can't used as integer key for subscription")
display("object {} can't be a key for subscription", typename)
}
IndexNotFound {
description("object doesn't have value at specified index")
}
OutputUnsupported(typename: &'static str) {
description("can't print object of this type")
display("can't print object of type {}", typename)
}
OutputError(typename: &'static str) {
description("error when formatting value")
display("error when formatting value of type {}", typename)
}
UnknownValidator(name: String) {
description("unknown validator")
display("validator {:?} is not defined", name)
}
RegexValidationError(data: String, regex: String) {
description("validation error")
display("output {:?} should match regex {:?}", data, regex)
}
BoolUnsupported(typename: &'static str) {
description("can't treat object of this type as bool")
display("can't treat object of type {} as bool", typename)
}
NumberUnsupported(typename: &'static str) {
description("can't treat object of this type as number")
display("can't treat object of type {} as number", typename)
}
ComparisonUnsupported(typename: &'static str) {
description("can't compare objects of this type")
display("can't compare objects of type {}", typename)
}
IterationUnsupported(typename: &'static str) {
description("can't iterate over the object")
display("can't iterate over the object of type {}", typename)
}
PairIterationUnsupported(typename: &'static str) {
description("can't iterate over the object by pairs")
display("can't iterate over the object by pairs of type {}",
typename)
}
VariableNotFound(name: String) {
description("variable or attribute not found")
display("variable or attribute {:?} not found", name)
}
Incomparable(left_type: &'static str, right_type: &'static str) {
description("two types can't be compared")
display("Can't compare object of type {:?} to {:?}",
left_type, right_type)
}
Custom(err: Box<Error>) {
description(err.description())
display("{}", err)
cause(&**err)
}
#[doc(hidden)]
__Nonexhaustive
}
}
quick_error! {
#[derive(Debug)]
pub enum RenderError {
Io(err: io::Error) {
display("I/O error: {}", err)
description("I/O error")
from()
}
Fmt(err: fmt::Error) {
description("error formatting value")
from()
}
Data(errs: Vec<(Pos, DataError)>) {
display("data error: {}", errs.iter()
.map(|&(p, ref e)| format!("{}: {}", p, e))
.collect::<Vec<_>>().join("\n "))
description("data error")
}
}
}