summaryrefslogtreecommitdiffstats
path: root/lib/entry/libimagentryref/src/error.rs
blob: c4152a14c03128d1ce6f5528fb2caf8c9ea7b675 (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//
// imag - the personal information management suite for the commandline
// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; version
// 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//

use std::error::Error;

use libimagerror::into::IntoError;

error_chain! {
    types {
        RefError, RefErrorKind, ResultExt, Result;
    }

    links {
        ListError(::libimagentrylist::error::ListError, ::libimagentrylist::error::ListErrorKind);
    }

    foreign_links {
        Io(::std::io::Error);
    }

    errors {
        StoreReadError          {
            description("Store read error")
            display("Store read error")
        }

        StoreWriteError         {
            description("Store write error")
            display("Store write error")
        }

        IOError                 {
            description("IO Error")
            display("IO Error")
        }

        UTF8Error               {
            description("UTF8 Error")
            display("UTF8 Error")
        }

        StoreIdError            {
            description("Error with storeid")
            display("Error with storeid")
        }

        HeaderTomlError         {
            description("Error while working with TOML Header")
            display("Error while working with TOML Header")
        }

        HeaderTypeError         {
            description("Header type error")
            display("Header type error")
        }

        HeaderFieldMissingError {
            description("Header field missing error")
            display("Header field missing error")
        }

        HeaderFieldWriteError   {
            description("Header field cannot be written")
            display("Header field cannot be written")
        }

        HeaderFieldReadError    {
            description("Header field cannot be read")
            display("Header field cannot be read")
        }

        HeaderFieldAlreadyExistsError {
            description("Header field already exists, cannot override")
            display("Header field already exists, cannot override")
        }

        PathUTF8Error {
            description("Path cannot be converted because of UTF8 Error")
            display("Path cannot be converted because of UTF8 Error")
        }

        PathHashingError {
            description("Path cannot be hashed")
            display("Path cannot be hashed")
        }

        PathCanonicalizationError {
            description("Path cannot be canonicalized")
            display("Path cannot be canonicalized")
        }

        TypeConversionError {
            description("Couldn't convert types")
            display("Couldn't convert types")
        }

        RefToDisplayError {
            description("Cannot convert Ref to string to show it to user")
            display("Cannot convert Ref to string to show it to user")
        }

        RefNotInStore {
            description("Ref/StoreId does not exist in store")
            display("Ref/StoreId does not exist in store")
        }

        RefTargetDoesNotExist       {
            description("Ref Target does not exist")
            display("Ref Target does not exist")
        }

        RefTargetPermissionError    {
            description("Ref Target permissions insufficient for referencing")
            display("Ref Target permissions insufficient for referencing")
        }

        RefTargetCannotBeHashed     {
            description("Ref Target cannot be hashed (is it a directory?)")
            display("Ref Target cannot be hashed (is it a directory?)")
        }

        RefTargetFileCannotBeOpened {
            description("Ref Target File cannot be open()ed")
            display("Ref Target File cannot be open()ed")
        }

        RefTargetCannotReadPermissions {
            description("Ref Target: Cannot read permissions")
            display("Ref Target: Cannot read permissions")
        }

        RefHashingError {
            description("Error while hashing")
            display("Error while hashing")
        }

    }
}

impl IntoError for RefErrorKind {
    type Target = RefError;

    fn into_error(self) -> Self::Target {
        RefError::from_kind(self)
    }

    fn into_error_with_cause(self, _: Box<Error>) -> Self::Target {
        RefError::from_kind(self)
    }
}