|
10 | 10 |
|
11 | 11 | #![allow(dead_code)] |
12 | 12 |
|
13 | | -use std; |
14 | | -use hyper; |
15 | | -use rusqlite; |
16 | | -use uuid; |
17 | | -use mentat_db; |
18 | | -use serde_cbor; |
19 | | -use serde_json; |
| 13 | +use failure::Error; |
20 | 14 |
|
21 | | -error_chain! { |
22 | | - types { |
23 | | - Error, ErrorKind, ResultExt, Result; |
24 | | - } |
25 | | - |
26 | | - foreign_links { |
27 | | - IOError(std::io::Error); |
28 | | - HttpError(hyper::Error); |
29 | | - HyperUriError(hyper::error::UriError); |
30 | | - SqlError(rusqlite::Error); |
31 | | - UuidParseError(uuid::ParseError); |
32 | | - Utf8Error(std::str::Utf8Error); |
33 | | - JsonError(serde_json::Error); |
34 | | - CborError(serde_cbor::error::Error); |
35 | | - } |
| 15 | +#[macro_export] |
| 16 | +macro_rules! bail { |
| 17 | + ($e:expr) => ( |
| 18 | + return Err($e.into()); |
| 19 | + ) |
| 20 | +} |
36 | 21 |
|
37 | | - links { |
38 | | - DbError(mentat_db::Error, mentat_db::ErrorKind); |
39 | | - } |
| 22 | +pub type Result<T> = ::std::result::Result<T, Error>; |
40 | 23 |
|
41 | | - errors { |
42 | | - TxIncorrectlyMapped(n: usize) { |
43 | | - description("encountered more than one uuid mapping for tx") |
44 | | - display("expected one, found {} uuid mappings for tx", n) |
45 | | - } |
| 24 | +#[derive(Debug, Fail)] |
| 25 | +pub enum TolstoyError { |
| 26 | + #[fail(display = "Received bad response from the server: {}", _0)] |
| 27 | + BadServerResponse(String), |
46 | 28 |
|
47 | | - UnexpectedState(t: String) { |
48 | | - description("encountered unexpected state") |
49 | | - display("encountered unexpected state: {}", t) |
50 | | - } |
| 29 | + #[fail(display = "encountered more than one metadata value for key: {}", _0)] |
| 30 | + DuplicateMetadata(String), |
51 | 31 |
|
52 | | - NotYetImplemented(t: String) { |
53 | | - description("not yet implemented") |
54 | | - display("not yet implemented: {}", t) |
55 | | - } |
| 32 | + #[fail(display = "transaction processor didn't say it was done")] |
| 33 | + TxProcessorUnfinished, |
56 | 34 |
|
57 | | - DuplicateMetadata(k: String) { |
58 | | - description("encountered more than one metadata value for key") |
59 | | - display("encountered more than one metadata value for key: {}", k) |
60 | | - } |
| 35 | + #[fail(display = "expected one, found {} uuid mappings for tx", _0)] |
| 36 | + TxIncorrectlyMapped(usize), |
61 | 37 |
|
62 | | - TxProcessorUnfinished { |
63 | | - description("Tx processor couldn't finish") |
64 | | - display("Tx processor couldn't finish") |
65 | | - } |
| 38 | + #[fail(display = "encountered unexpected state: {}", _0)] |
| 39 | + UnexpectedState(String), |
66 | 40 |
|
67 | | - BadServerResponse(s: String) { |
68 | | - description("Received bad response from the server") |
69 | | - display("Received bad response from the server: {}", s) |
70 | | - } |
71 | | - } |
| 41 | + #[fail(display = "not yet implemented: {}", _0)] |
| 42 | + NotYetImplemented(String), |
72 | 43 | } |
0 commit comments