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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
//
// imag - the personal information management suite for the commandline
// Copyright (C) 2015-2018 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::path::PathBuf;

use storeid::StoreId;

error_chain! {
    types {
        StoreError, StoreErrorKind, ResultExt, Result;
    }

    foreign_links {
        Io(::std::io::Error);
        Fmt(::std::fmt::Error);
        TomlDeserError(::toml::de::Error);
        GlobPatternError(::glob::PatternError);
        TomlQueryError(::toml_query::error::Error);
    }

    errors {

        ConfigurationError      {
            description("Store Configuration Error")
            display("Store Configuration Error")
        }

        ConfigTypeError(key: &'static str, expected: &'static str) {
            description("Store configuration type error")
            display("Store configuration type error at '{}', expected {}", key, expected)
        }

        ConfigKeyMissingError(key: &'static str) {
            description("Configuration Key missing")
            display("Configuration Key missing: '{}'", key)
        }

        VersionError            {
            description("Incompatible store versions detected")
            display("Incompatible store versions detected")
        }

        CreateStoreDirDenied    {
            description("Creating store directory implicitely denied")
            display("Creating store directory implicitely denied")
        }

        FileError               {
            description("File Error")
            display("File Error")
        }

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

        IdLocked                {
            description("ID locked")
            display("ID locked")
        }

        IdNotFound(sid: StoreId) {
            description("ID not found")
            display("ID not found: {}", sid)
        }

        FileNotFound            {
            description("File corresponding to ID not found")
            display("File corresponding to ID not found")
        }

        FileNotCreated          {
            description("File corresponding to ID could not be created")
            display("File corresponding to ID could not be created")
        }

        FileNotWritten          {
            description("File corresponding to ID could not be written to")
            display("File corresponding to ID could not be written to")
        }

        FileNotSeeked           {
            description("File corresponding to ID could not be seeked")
            display("File corresponding to ID could not be seeked")
        }

        FileNotRemoved          {
            description("File corresponding to ID could not be removed")
            display("File corresponding to ID could not be removed")
        }

        FileNotRenamed          {
            description("File corresponding to ID could not be renamed")
            display("File corresponding to ID could not be renamed")
        }

        FileNotCopied           {
            description("File could not be copied")
            display("File could not be copied")
        }

        DirNotCreated           {
            description("Directory/Directories could not be created")
            display("Directory/Directories could not be created")
        }

        StorePathExists(pb: PathBuf) {
            description("Store path exists")
            display("Store path exists: {:?}", pb)
        }

        StorePathCreate(pb: PathBuf) {
            description("Store path create")
            display("Store path create: {:?}", pb)
        }

        LockError               {
            description("Error locking datastructure")
            display("Error locking datastructure")
        }

        LockPoisoned            {
            description("The internal Store Lock has been poisoned")
            display("The internal Store Lock has been poisoned")
        }

        EntryAlreadyBorrowed(id: StoreId) {
            description("Entry is already borrowed")
            display("Entry is already borrowed: {:?}", id)
        }

        EntryAlreadyExists(id: StoreId) {
            description("Entry already exists")
            display("Entry already exists: {:?}", id)
        }

        MalformedEntry          {
            description("Entry has invalid formatting, missing header")
            display("Entry has invalid formatting, missing header")
        }

        HeaderTypeFailure       {
            description("Header type is wrong")
            display("Header type is wrong")
        }

        EncodingError           {
            description("Encoding error")
            display("Encoding error")
        }

        EntryRenameError(old: PathBuf, new: PathBuf) {
            description("Entry rename error")
            display("Entry rename error: {:?} -> {:?}", old, new)
        }

        StoreIdHandlingError    {
            description("StoreId handling error")
            display("StoreId handling error")
        }

        StoreIdLocalPartAbsoluteError(pb: PathBuf) {
            description("StoreId 'id' part is absolute (starts with '/') which is not allowed")
            display("StoreId 'id' part is absolute (starts with '/') which is not allowed: {:?}", pb)
        }

        StoreIdBuildFromFullPathError {
            description("Building StoreId from full file path failed")
            display("Building StoreId from full file path failed")
        }

        StoreIdHasNoBaseError(pb: PathBuf) {
            description("StoreId has no 'base' part")
            display("StoreId has no 'base' part: {:?}", pb)
        }

        CreateCallError            {
            description("Error when calling create()")
            display("Error when calling create()")
        }

        RetrieveCallError          {
            description("Error when calling retrieve()")
            display("Error when calling retrieve()")
        }

        GetCallError               {
            description("Error when calling get()")
            display("Error when calling get()")
        }

        GetAllVersionsCallError    {
            description("Error when calling get_all_versions()")
            display("Error when calling get_all_versions()")
        }

        RetrieveForModuleCallError {
            description("Error when calling retrieve_for_module()")
            display("Error when calling retrieve_for_module()")
        }

        UpdateCallError            {
            description("Error when calling update()")
            display("Error when calling update()")
        }

        RetrieveCopyCallError      {
            description("Error when calling retrieve_copy()")
            display("Error when calling retrieve_copy()")
        }

        DeleteCallError            {
            description("Error when calling delete()")
            display("Error when calling delete()")
        }

        MoveCallError              {
            description("Error when calling move()")
            display("Error when calling move()")
        }

        MoveByIdCallError          {
            description("Error when calling move_by_id()")
            display("Error when calling move_by_id()")
        }

        // Parser-related errors

        MissingMainSection  {
            description("Missing main section")
            display("Missing main section")
        }

        MissingVersionInfo  {
            description("Missing version information in main section")
            display("Missing version information in main section")
        }

        NonTableInBaseTable {
            description("A non-table was found in the base table")
            display("A non-table was found in the base table")
        }

        HeaderInconsistency {
            description("The header is inconsistent")
            display("The header is inconsistent")
        }
    }
}