C++11 tidying.
[dcpomatic.git] / src / lib / exceptions.h
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 /** @file  src/lib/exceptions.h
23  *  @brief Our exceptions.
24  */
25
26
27 #ifndef DCPOMATIC_EXCEPTIONS_H
28 #define DCPOMATIC_EXCEPTIONS_H
29
30
31 #include "compose.hpp"
32 extern "C" {
33 #include <libavutil/pixfmt.h>
34 }
35 #include <boost/filesystem.hpp>
36 #include <boost/optional.hpp>
37 #include <cstring>
38 #include <stdexcept>
39
40
41 /** @class DecodeError
42  *  @brief A low-level problem with the decoder (possibly due to the nature
43  *  of a source file).
44  */
45 class DecodeError : public std::runtime_error
46 {
47 public:
48         explicit DecodeError (std::string s)
49                 : std::runtime_error (s)
50         {}
51
52         DecodeError (std::string function, std::string caller)
53                 : std::runtime_error (String::compose("%1 failed [%2", function, caller))
54         {}
55
56         DecodeError (std::string function, std::string caller, int error)
57                 : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error))
58         {}
59 };
60
61
62 class CryptoError : public std::runtime_error
63 {
64 public:
65         explicit CryptoError (std::string s)
66                 : std::runtime_error (s)
67         {}
68 };
69
70
71 /** @class EncodeError
72  *  @brief A low-level problem with an encoder.
73  */
74 class EncodeError : public std::runtime_error
75 {
76 public:
77         explicit EncodeError (std::string s)
78                 : std::runtime_error (s)
79         {}
80
81         explicit EncodeError (std::string function, std::string caller)
82                 : std::runtime_error (String::compose("%1 failed [%2]", function, caller))
83         {}
84
85         explicit EncodeError (std::string function, std::string caller, int error)
86                 : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error))
87         {}
88 };
89
90
91 /** @class FileError.
92  *  @brief Parent class for file-related errors.
93  */
94 class FileError : public std::runtime_error
95 {
96 public:
97         /** @param m Error message.
98          *  @param f Name of the file that this exception concerns.
99          */
100         FileError (std::string m, boost::filesystem::path f)
101                 : std::runtime_error (String::compose("%1 with %2", m, f.string()))
102                 , _file (f)
103         {}
104
105         virtual ~FileError () throw () {}
106
107         /** @return name of the file that this exception concerns */
108         boost::filesystem::path file () const {
109                 return _file;
110         }
111
112 private:
113         /** name of the file that this exception concerns */
114         boost::filesystem::path _file;
115 };
116
117
118 class JoinError : public std::runtime_error
119 {
120 public:
121         explicit JoinError (std::string s)
122                 : std::runtime_error (s)
123         {}
124 };
125
126
127 /** @class OpenFileError.
128  *  @brief Indicates that some error occurred when trying to open a file.
129  */
130 class OpenFileError : public FileError
131 {
132 public:
133         enum Mode {
134                 READ,
135                 WRITE,
136                 READ_WRITE
137         };
138
139         /** @param f File that we were trying to open.
140          *  @param error Code of error that occurred.
141          *  @param mode Mode that we tried to open the file in.
142          */
143         OpenFileError (boost::filesystem::path f, int error, Mode mode);
144 };
145
146
147 class FileNotFoundError : public std::runtime_error
148 {
149 public:
150         FileNotFoundError (boost::filesystem::path f);
151         virtual ~FileNotFoundError () throw () {}
152
153         /** @return name of the file that this exception concerns */
154         boost::filesystem::path file () const {
155                 return _file;
156         }
157
158 private:
159         /** name of the file that this exception concerns */
160         boost::filesystem::path _file;
161 };
162
163
164 /** @class ReadFileError.
165  *  @brief Indicates that some error occurred when trying to read from a file
166  */
167 class ReadFileError : public FileError
168 {
169 public:
170         /** @param f File that we were trying to read from.
171          *  @param e errno value, or 0.
172          */
173         ReadFileError (boost::filesystem::path f, int e = 0);
174 };
175
176
177 /** @class WriteFileError.
178  *  @brief Indicates that some error occurred when trying to write to a file
179  */
180 class WriteFileError : public FileError
181 {
182 public:
183         /** @param f File that we were trying to write to.
184          *  @param e errno value, or 0.
185          */
186         WriteFileError (boost::filesystem::path f, int e);
187 };
188
189
190 /** @class SettingError.
191  *  @brief Indicates that something is wrong with a setting.
192  */
193 class SettingError : public std::runtime_error
194 {
195 public:
196         /** @param s Name of setting that was required.
197          *  @param m Message.
198          */
199         SettingError (std::string s, std::string m)
200                 : std::runtime_error (m)
201                 , _setting (s)
202         {}
203
204         virtual ~SettingError () throw () {}
205
206         /** @return name of setting in question */
207         std::string setting () const {
208                 return _setting;
209         }
210
211 private:
212         std::string _setting;
213 };
214
215
216 /** @class MissingSettingError.
217  *  @brief Indicates that a Film is missing a setting that is required for some operation.
218  */
219 class MissingSettingError : public SettingError
220 {
221 public:
222         /** @param s Name of setting that was required */
223         explicit MissingSettingError (std::string s);
224 };
225
226
227 /** @class BadSettingError
228  *  @brief Indicates that a setting is bad in some way.
229  */
230 class BadSettingError : public SettingError
231 {
232 public:
233         /** @param s Name of setting that is bad.
234          *  @param m Error message.
235          */
236         BadSettingError (std::string s, std::string m)
237                 : SettingError (s, m)
238         {}
239 };
240
241
242 /** @class NetworkError
243  *  @brief Indicates some problem with communication on the network.
244  */
245 class NetworkError : public std::runtime_error
246 {
247 public:
248         explicit NetworkError (std::string s)
249                 : std::runtime_error (s)
250         {}
251 };
252
253
254 /** @class KDMError
255  *  @brief A problem with a KDM.
256  */
257 class KDMError : public std::runtime_error
258 {
259 public:
260         KDMError (std::string s, std::string d);
261         ~KDMError () throw() {}
262
263         std::string summary () const {
264                 return _summary;
265         }
266
267         std::string detail () const {
268                 return _detail;
269         }
270
271 private:
272         std::string _summary;
273         std::string _detail;
274 };
275
276
277 /** @class PixelFormatError
278  *  @brief A problem with an unsupported pixel format.
279  */
280 class PixelFormatError : public std::runtime_error
281 {
282 public:
283         PixelFormatError (std::string o, AVPixelFormat f);
284 };
285
286
287 /** @class TextSubtitleError
288  *  @brief An error that occurs while parsing a TextSubtitleError file.
289  */
290 class TextSubtitleError : public FileError
291 {
292 public:
293         TextSubtitleError (std::string, std::string, boost::filesystem::path);
294 };
295
296
297 class DCPError : public std::runtime_error
298 {
299 public:
300         explicit DCPError (std::string s)
301                 : std::runtime_error (s)
302         {}
303 };
304
305
306 /** @class ProjectFolderError
307  *  @brief An attempt has been made to read a DCP from a directory, but it looks
308  *  like the directory actually contains a DCP-o-matic project.
309  */
310 class ProjectFolderError : public DCPError
311 {
312 public:
313         /* Code which catches this exception will provide their own message */
314         ProjectFolderError ()
315                 : DCPError ("dummy")
316         {}
317 };
318
319
320 class InvalidSignerError : public std::runtime_error
321 {
322 public:
323         InvalidSignerError ();
324         explicit InvalidSignerError (std::string reason);
325 };
326
327 class ProgrammingError : public std::runtime_error
328
329 {
330 public:
331         ProgrammingError (std::string file, int line, std::string message = "");
332 };
333
334
335 class TextEncodingError : public std::runtime_error
336 {
337 public:
338         explicit TextEncodingError (std::string s)
339                 : std::runtime_error (s)
340         {}
341 };
342
343
344 class MetadataError : public std::runtime_error
345 {
346 public:
347         explicit MetadataError (std::string s)
348                 : std::runtime_error (s)
349         {}
350 };
351
352
353 class OldFormatError : public std::runtime_error
354 {
355 public:
356         explicit OldFormatError (std::string s)
357                 : std::runtime_error (s)
358         {}
359 };
360
361
362 class KDMAsContentError : public std::runtime_error
363 {
364 public:
365         KDMAsContentError ();
366 };
367
368
369 class GLError : public std::runtime_error
370 {
371 public:
372         GLError (char const * last, int e);
373 };
374
375
376 /** @class CopyError
377  *  @brief An error which occurs when copying a DCP to a distribution drive.
378  */
379 class CopyError : public std::runtime_error
380 {
381 public:
382         CopyError (std::string s, boost::optional<int> n = boost::optional<int>());
383         virtual ~CopyError () throw () {}
384
385         std::string message () const {
386                 return _message;
387         }
388
389         boost::optional<int> number () const {
390                 return _number;
391         }
392
393 private:
394         std::string _message;
395         boost::optional<int> _number;
396 };
397
398
399 /** @class CommunicationFailedError
400  *  @brief Communcation between dcpomatic2_disk and _disk_writer failed somehow.
401  */
402 class CommunicationFailedError : public CopyError
403 {
404 public:
405         CommunicationFailedError ();
406 };
407
408
409 /** @class VerifyError
410  *  @brief An error which occurs when verifying a DCP that we copied to a distribution drive.
411  */
412 class VerifyError : public std::runtime_error
413 {
414 public:
415         VerifyError (std::string s, int n);
416         virtual ~VerifyError () throw () {}
417
418         std::string message () const {
419                 return _message;
420         }
421
422         int number () const {
423                 return _number;
424         }
425
426 private:
427         std::string _message;
428         int _number;
429 };
430
431
432 class PrivilegeError : public std::runtime_error
433 {
434 public:
435         explicit PrivilegeError (std::string s)
436                         : std::runtime_error (s)
437                 {}
438 };
439
440
441 #endif