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
268
269
270
271
272
273
274
275
use serde_json;
use std::fs::File;
use std::io;
use std::path::PathBuf;

error_chain! {
    types { }

    links { }

    foreign_links {
        io::Error, IoError;
        serde_json::Error, SerdeJsonError;
    }

    errors {
        AbsolutePathNotFound(path: PathBuf) {
            description("Error locating absolute path. The path does not exist.")
            display(
                "{}{}{}",
                "Error locating absolute path. The path, '",
                path.to_string_lossy(),
                "', does not exist.",
            )
        }

        DependencyHasNoName(path: PathBuf) {
            description("Error loading dependency. The dependency has no name.")
            display(
                "{}{}{}",
                "Error loading dependency at path, '",
                path.to_string_lossy(),
                "'. The dependnecy has no name.",
            )
        }

        DependencyHasNoVersion(name: String, path: PathBuf) {
            description("Error loading dependency. The dependency has no version.")
            display(
                "{}{}{}{}{}",
                "Error loading dependency, '",
                name,
                "' at path, '",
                path.to_string_lossy(),
                "'. The dependnecy has no version.",
            )
        }

        FileFromPathFailure(path: PathBuf) {
            description("Error opening file. The file could not be opened.")
            display(
                "{}{}{}",
                "Error opending file at path, '",
                path.to_string_lossy(),
                "'. The file could not be opended.",
            )
        }

        FileNotFoundInPlugin(file: PathBuf, full_path: PathBuf) {
            description("Error locating file in plugin. The file does not exist.")
            display(
                "{}{}{}{}{}",
                "Error locating file in plugin. The file, '",
                file.to_string_lossy(),
                "', does not exist at '",
                full_path.to_string_lossy(),
                "'.",
            )
        }

        NotImplemented(description: String, display: String) {
            description(description)
            display(
                "{}",
                display,
            )
        }

        ModuleFolderNotFound(module_id: usize) {
            description("The module folder could not be found.")
            display(
                "{}{}{}",
                "The module folder with id, '",
                module_id,
                "could not be found.",
            )
        }

        PathVerificationNotAbsolute(path: PathBuf) {
            description("Error verifying path. To path is not absolute.")
            display(
                "{}{}{}",
                "Error verifying path. The path, '",
                path.to_string_lossy(),
                "', is not absolute.",
            )
        }

        PathVerificationNotDirectory(path: PathBuf) {
            description("Error verifying path. To path is not a directory.")
            display(
                "{}{}{}",
                "Error verifying path. The path, '",
                path.to_string_lossy(),
                "', is not a directory.",
            )
        }

        PathVerificationNotExist(path: PathBuf) {
            description("Error verifying path. To path is does not exist.")
            display(
                "{}{}{}",
                "Error verifying path. The path, '",
                path.to_string_lossy(),
                "', does not exist.",
            )
        }

        PathVerificationNotFile(path: PathBuf) {
            description("Error verifying path. To path is not a file.")
            display(
                "{}{}{}",
                "Error verifying path. The path, '",
                path.to_string_lossy(),
                "', is not a file.",
            )
        }

        PluginDeserializationFailure(plugin_text: String) {
            description("Error deserializing plugin text. The plugin text could not be deserialized.")
            display(
                "{}{}{}",
                "Error deserializing plugin text:\n",
                plugin_text,
                "\nThe plugin text could not be deserialized.",
            )
        }

        PluginLoadNameCollision(name: String) {
            description("Error loading plugin. A plugin with the specified name has already been loaded.")
            display(
                "{}{}{}",
                "Error loading plugin with name, '",
                name,
                "'. A plugin with the specified name has already been loaded.",
            )
        }

        PluginLoadPathCollision(path: PathBuf) {
            description("Error loading plugin. A plugin at the specified path has already been loaded.")
            display(
                "{}{}{}",
                "Error loading plugin at path, '",
                path.to_string_lossy(),
                "'. A plugin at the specified path has already been loaded.",
            )
        }

        PluginNotFoundInPluginMap(plugin_name: String) {
            description("Error locating plugin in plugin map. The plugin could not be found.")
            display(
                "{}{}{}",
                "Error locating plugin with name, '",
                plugin_name,
                "', in plugin map. The plugin could not be found.",
            )
        }

        PluginPathIdIncorrect(path: PathBuf, plugin_id: usize, next_id: usize) {
            description("Error adding plugin path. A plugin with the current id cannot be added.")
            display(
                "{}{}{}{}{}{}{}",
                "Error adding plugin path, '",
                path.to_string_lossy(),
                "'. A plugin with path with the id, '",
                plugin_id,
                "', cannot be added. The next plugin id should be, '",
                next_id,
                "'.",
            )
        }

        PluginPathNotFound(file: PathBuf, plugin_id: usize) {
            description("Error finding plugin path for file. A plugin the requested id does not exist.")
            display(
                "{}{}{}{}{}",
                "Error finding plugin path for file, '",
                file.to_string_lossy(),
                "'. A plugin with the requested id, '",
                plugin_id,
                "', does not exist.",
            )
        }

        RelativePathNotFound(path: PathBuf, search_paths: Vec<PathBuf>) {
            description("Error locating relative path. The path does not exist.")
            display(
                "{}{}{}{}",
                "Error locating relative path, '",
                path.to_string_lossy(),
                "', the path could not be found. The following paths were searched:",
                {
                    let mut result = String::new();
                    for search_path in search_paths {
                        let this_result =
                            format!(
                                "{}{}{}",
                                "\n'",
                                search_path.to_string_lossy(),
                                "'",
                            );
                        result.push_str(&this_result);
                    }
                    result
                },
            )
        }

        SubmoduleNotExist(module_id: usize, submodule_id: usize) {
            description("The submodule does not exist.")
            display(
                "{}{}{}{}{}",
                "Error locating with id, '",
                submodule_id,
                "', while searching in module with id, '",
                module_id,
                "'. The submodule does not exist.",
            )
        }

        SubmodulePathNoModule(module_id: usize, submodule_id: usize, path: PathBuf) {
            description("Error locating submodule path. The module id containing the submodule is invalid.")
            display(
                "{}{}{}{}{}{}{}",
                "Error locating submodule path. The module id, ",
                module_id,
                ", containing the submodule with id, ",
                submodule_id,
                ", cannot be found. The search path is, '",
                path.to_string_lossy(),
                "'.",
            )
        }

        SubmodulePathNoSubmodule(module_path: PathBuf, submodule_id: usize, path: PathBuf) {
            description("Error locating submodule path. The submodule id is invalid.")
            display(
                "{}{}{}",
                "Error locating submodule path. The submodule id, ",
                submodule_id,
                ", cannot be found.",
            )
        }

        SubmodulePathNotExist(module_id: usize, submodule: String, path: PathBuf) {
            description("Error locating submodule path. The submodule path does not exist.")
            display(
                "{}{}{}",
                "Error locating submodule path. The submodule path, ",
                path.to_string_lossy(),
                ", does not exist.",
            )
        }

        TextFromFileFailure(file: File) {
            description("Error reading text from file. The file could not be read.")
            display(
                "{}{:?}{}",
                "Error reading text from file:\n",
                file,
                "\nThe file could not be read. Cause:\n",
            )
        }
    }
}