serde_avro/
error.rs

1use serde;
2use serde_json;
3use std::fmt;
4use std::io;
5use std::string;
6
7error_chain! {
8    foreign_links {
9        IO(io::Error);
10        Utf8(string::FromUtf8Error);
11        JsonDecode(serde_json::Error);
12    }
13
14    errors {
15        NoSuchType(type_name: String) {
16            description("no such type")
17            display("no such type: {:?}", type_name)
18        }
19        InvalidSchema {
20            description("invalid schema")
21            display("invalid schema")
22        }
23        BadFileMagic(magic: Vec<u8>) {
24            description("bad file magic")
25            display("bad file magic: {:?}", magic)
26        }
27        NoSchema {
28            description("the container has no schema")
29            display("the container has no schema")
30        }
31        NoRootType {
32            description("the container schema has no root type")
33            display("the container schema has no root type")
34        }
35        UnsupportedCodec(codec: String) {
36            description("unsupported codec")
37            display("unsupported codec: {:?}", codec)
38        }
39        FieldTypeMismatch(field: &'static str, expected: &'static str) {
40            description("unexpected field type")
41            display("the value for {:?} was not a {}", field, expected)
42        }
43        RequiredFieldMissing(field: &'static str) {
44            description("required field missing")
45            display("the {:?} field is required", field)
46        }
47        DuplicateSchema(name: String) {
48            description("there are two schemata with the same name")
49            display("there are two schemata called {:?}", name)
50        }
51        EndOfStream {
52            description("end of stream")
53            display("end of stream")
54        }
55        IntegerOverflow {
56            description("integer overflow")
57            display("integer overflow")
58        }
59        NegativeLength {
60            description("negative length")
61            display("negative length")
62        }
63    }
64}
65
66impl serde::de::Error for Error {
67    fn custom<T>(msg: T) -> Error
68        where T: fmt::Display
69    {
70        format!("{}", msg).into()
71    }
72}