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
//! Error module
//! y u do this???
//!
//! This should make errors useable! Yay!
use interface::*;

error_chain! {
    types {
        Error, ErrorKind, ResultExt;
    }

    errors {
        TooBig(given: Addr, max: Addr) {
            description("given address too big")
            display("MemoryBlock Error: {:#X} is too big, {:#X} is the maximum", given, max)
        }
        TooSmall(given: Addr, min: Addr) {
            description("given address too small")
            display("MemoryBlock Error: {:#X} is too small, {:#X} is the minimum", given, min)
        }
        InvalidAddr(addr: Addr) {
            description("invalid address")
            display("MemoryBlock Error: Invalid address: {:#X}", addr)
        }
        ReadOnly(at: Addr, _globally: bool) {
            description("read only")
            display("MemoryBlock Error: Read only at {:#X}", at)
        }
        WriteOnly(at: Addr, _globally: bool) {
            description("write only")
            display("MemoryBlock Error: Write only at {:#X}", at)
        }
        UnalignedAccess(given: Addr, alignment: Addr) {
            description("unaligned access")
            display("MemoryBlock Error: Unaligned access at {:#X}, need {} byte alignment", given, alignment)
        }
        NoData(at: Addr) {
            description("no data")
            display("MemoryBlock Error: No data available at {:#X}", at)
        }
        InvalidData(at: Addr) {
            description("invalid data")
            display("MemoryBlock Error: {:#X}: Invalid data", at)
        }
        HardwareFault(at: Addr, reason: &'static str) {
            description("hardware fault")
            display("MemoryBlock Error: Hardware Fault at {:#X}: {}", at, reason)
        }
        Uninitialized(at: Addr) {
            description("uninitialized")
            display("MemoryBlock Error: {:#X} is uninitialized", at)
        }
        NotImplemented {
            description("not implemented")
            display("MemoryBlock Error: Not implemented")
        }
        NotApplicable(at: Addr) {
            description("not applicable")
            display("MemoryBlock Error: Action not applicable at {:#X}", at)
        }

        EndianessHelperFail(helpername: &'static str, at: Addr, in_byte: Addr) {
            description("error in endian helper")
            display("MemoryBlock Error: Failure in {} @ {:#X}, in byte {}", helpername, at, in_byte)
        }
    }
}