1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use types::parser::{Case, SourceFormat};
use failure::Error;
use eval;

/// Errors associated with the properties of style
#[derive(Debug, Fail, PartialEq)]
pub enum PropertyError {
    #[fail(display = "invalid property type for {} - expected {}", property, expected)]
    InvalidType {
        property: String,
        expected: String,
    },

    #[fail(display = "invalid property key {}", key)]
    InvalidKey {
        key: String,
    },

    #[fail(display = "invalid property '{}' case, need: {:?}", key, case)]
    InvalidKeyCase {
        case: Case,
        key: String,
    },

    #[fail(display = "invalid expression '{}': {:?}", key, error)]
    InvalidExpression {
        error: eval::Error,
        key: String,
    },

    #[fail(display = "unknown '{}' key (or not associated with `FlexStyle` properties)", key)]
    SharedUnitConvert {
        key: String,
    },
}

/// Errors associated with style parsing
#[derive(Debug, Fail)]
pub enum ParseError {
    #[fail(display = "invalid {:?}: {:?}", source_type, error)]
    InvalidSource {
        source_type: SourceFormat,
        error: Error,
    },

    #[fail(display = "invalid {:?} value for property '{}': {:?}", source_type, property, error)]
    InvalidValue {
        source_type: SourceFormat,
        property: String,
        error: Error,
    },

    #[fail(display = "error with deserialize `{}` into {}: {:?}", key, target, error)]
    DeserializeError {
        target: String,
        error: Error,
        key: String,
    },

    #[fail(display = "missing custom middleware \"{}\"", name)]
    MissingMiddleware {
        name: String,
    },

    #[fail(display = "{:?}", error)]
    PropertyError {
        error: PropertyError,
    },

    #[fail(display = "error: '{}'", error)]
    CustomError {
        error: String,
    },

    #[fail(display = "missing state key `{}` in style", name)]
    StateMissing {
        name: String,
    },
}

/// Errors associated with the finalized calculation of properties
#[derive(Debug, Fail)]
pub enum ProcessingError {
    #[fail(display = "failed run expression for `{}` in style: {:#?}", property, error)]
    ExecFailed {
        error: eval::Error,
        property: String,
    },

    #[fail(display = "invalid type `{}` - expected {}", property, expected)]
    InvalidType {
        property: String,
        expected: String,
    },
}