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
//! Dynomite error types

/// Errors that may result of attribute value conversions
#[derive(Debug, Fail, PartialEq)]
pub enum AttributeError {
    /// Will be returned if an AttributeValue is present, and is of the expected
    /// type but its contents are not well-formatted
    #[fail(display = "Invalid format")]
    InvalidFormat,
    /// Will be returned if provided AttributeValue is not of the expected type
    #[fail(display = "Invalid type")]
    InvalidType,
    /// Will be returned if provided attributes does not included an
    /// expected named value
    #[fail(display = "Missing field {}", name)]
    MissingField {
        /// Name of the field that is missing
        name: String,
    },
}

#[cfg(test)]
mod tests {
    use super::AttributeError;
    #[test]
    fn invalid_format_displays() {
        assert_eq!(
            "Invalid format",
            format!("{}", AttributeError::InvalidFormat)
        )
    }

    #[test]
    fn invalid_type_displays() {
        assert_eq!("Invalid type", format!("{}", AttributeError::InvalidType))
    }

    #[test]
    fn missing_field_displays() {
        assert_eq!(
            "Missing field foo",
            format!("{}", AttributeError::MissingField { name: "foo".into() })
        )
    }
}