Fix the build for older macOS.
[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         DecodeError (std::string function, std::string caller, boost::filesystem::path file)
61                 : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, file.string()))
62         {}
63
64         DecodeError (std::string function, std::string caller, int error, boost::filesystem::path file)
65                 : std::runtime_error (String::compose("%1 failed [%2] (%3) (%4)", function, caller, error, file.string()))
66         {}
67 };
68
69
70 class CryptoError : public std::runtime_error
71 {
72 public:
73         explicit CryptoError (std::string s)
74                 : std::runtime_error (s)
75         {}
76 };
77
78
79 /** @class EncodeError
80  *  @brief A low-level problem with an encoder.
81  */
82 class EncodeError : public std::runtime_error
83 {
84 public:
85         explicit EncodeError (std::string s)
86                 : std::runtime_error (s)
87         {}
88
89         explicit EncodeError (std::string function, std::string caller)
90                 : std::runtime_error (String::compose("%1 failed [%2]", function, caller))
91         {}
92
93         explicit EncodeError (std::string function, std::string caller, int error)
94                 : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error))
95         {}
96 };
97
98
99 /** @class FileError.
100  *  @brief Parent class for file-related errors.
101  */
102 class FileError : public std::runtime_error
103 {
104 public:
105         /** @param m Error message.
106          *  @param f Name of the file that this exception concerns.
107          */
108         FileError (std::string m, boost::filesystem::path f)
109                 : std::runtime_error (String::compose("%1 with %2", m, f.string()))
110                 , _file (f)
111         {}
112
113         virtual ~FileError () throw () {}
114
115         /** @return name of the file that this exception concerns */
116         boost::filesystem::path file () const {
117                 return _file;
118         }
119
120 private:
121         /** name of the file that this exception concerns */
122         boost::filesystem::path _file;
123 };
124
125
126 class JoinError : public std::runtime_error
127 {
128 public:
129         explicit JoinError (std::string s)
130                 : std::runtime_error (s)
131         {}
132 };
133
134
135 /** @class OpenFileError.
136  *  @brief Indicates that some error occurred when trying to open a file.
137  */
138 class OpenFileError : public FileError
139 {
140 public:
141         enum Mode {
142                 READ,
143                 WRITE,
144                 READ_WRITE
145         };
146
147         /** @param f File that we were trying to open.
148          *  @param error Code of error that occurred.
149          *  @param mode Mode that we tried to open the file in.
150          */
151         OpenFileError (boost::filesystem::path f, int error, Mode mode);
152 };
153
154
155 class FileNotFoundError : public std::runtime_error
156 {
157 public:
158         FileNotFoundError (boost::filesystem::path f);
159         virtual ~FileNotFoundError () throw () {}
160
161         /** @return name of the file that this exception concerns */
162         boost::filesystem::path file () const {
163                 return _file;
164         }
165
166 private:
167         /** name of the file that this exception concerns */
168         boost::filesystem::path _file;
169 };
170
171
172 /** @class ReadFileError.
173  *  @brief Indicates that some error occurred when trying to read from a file
174  */
175 class ReadFileError : public FileError
176 {
177 public:
178         /** @param f File that we were trying to read from.
179          *  @param e errno value, or 0.
180          */
181         ReadFileError (boost::filesystem::path f, int e = 0);
182 };
183
184
185 /** @class WriteFileError.
186  *  @brief Indicates that some error occurred when trying to write to a file
187  */
188 class WriteFileError : public FileError
189 {
190 public:
191         /** @param f File that we were trying to write to.
192          *  @param e errno value, or 0.
193          */
194         WriteFileError (boost::filesystem::path f, int e);
195 };
196
197
198 /** @class SettingError.
199  *  @brief Indicates that something is wrong with a setting.
200  */
201 class SettingError : public std::runtime_error
202 {
203 public:
204         /** @param s Name of setting that was required.
205          *  @param m Message.
206          */
207         SettingError (std::string s, std::string m)
208                 : std::runtime_error (m)
209                 , _setting (s)
210         {}
211
212         virtual ~SettingError () throw () {}
213
214         /** @return name of setting in question */
215         std::string setting () const {
216                 return _setting;
217         }
218
219 private:
220         std::string _setting;
221 };
222
223
224 /** @class MissingSettingError.
225  *  @brief Indicates that a Film is missing a setting that is required for some operation.
226  */
227 class MissingSettingError : public SettingError
228 {
229 public:
230         /** @param s Name of setting that was required */
231         explicit MissingSettingError (std::string s);
232 };
233
234
235 /** @class BadSettingError
236  *  @brief Indicates that a setting is bad in some way.
237  */
238 class BadSettingError : public SettingError
239 {
240 public:
241         /** @param s Name of setting that is bad.
242          *  @param m Error message.
243          */
244         BadSettingError (std::string s, std::string m)
245                 : SettingError (s, m)
246         {}
247 };
248
249
250 /** @class NetworkError
251  *  @brief Indicates some problem with communication on the network.
252  */
253 class NetworkError : public std::runtime_error
254 {
255 public:
256         explicit NetworkError (std::string s)
257                 : std::runtime_error (s)
258         {}
259 };
260
261
262 /** @class KDMError
263  *  @brief A problem with a KDM.
264  */
265 class KDMError : public std::runtime_error
266 {
267 public:
268         KDMError (std::string s, std::string d);
269         ~KDMError () throw() {}
270
271         std::string summary () const {
272                 return _summary;
273         }
274
275         std::string detail () const {
276                 return _detail;
277         }
278
279 private:
280         std::string _summary;
281         std::string _detail;
282 };
283
284
285 /** @class PixelFormatError
286  *  @brief A problem with an unsupported pixel format.
287  */
288 class PixelFormatError : public std::runtime_error
289 {
290 public:
291         PixelFormatError (std::string o, AVPixelFormat f);
292 };
293
294
295 /** @class TextSubtitleError
296  *  @brief An error that occurs while parsing a TextSubtitleError file.
297  */
298 class TextSubtitleError : public FileError
299 {
300 public:
301         TextSubtitleError (std::string, std::string, boost::filesystem::path);
302 };
303
304
305 class DCPError : public std::runtime_error
306 {
307 public:
308         explicit DCPError (std::string s)
309                 : std::runtime_error (s)
310         {}
311 };
312
313
314 /** @class ProjectFolderError
315  *  @brief An attempt has been made to read a DCP from a directory, but it looks
316  *  like the directory actually contains a DCP-o-matic project.
317  */
318 class ProjectFolderError : public DCPError
319 {
320 public:
321         /* Code which catches this exception will provide their own message */
322         ProjectFolderError ()
323                 : DCPError ("dummy")
324         {}
325 };
326
327
328 class InvalidSignerError : public std::runtime_error
329 {
330 public:
331         InvalidSignerError ();
332         explicit InvalidSignerError (std::string reason);
333 };
334
335 class ProgrammingError : public std::runtime_error
336
337 {
338 public:
339         ProgrammingError (std::string file, int line, std::string message = "");
340 };
341
342
343 class TextEncodingError : public std::runtime_error
344 {
345 public:
346         explicit TextEncodingError (std::string s)
347                 : std::runtime_error (s)
348         {}
349 };
350
351
352 class MetadataError : public std::runtime_error
353 {
354 public:
355         explicit MetadataError (std::string s)
356                 : std::runtime_error (s)
357         {}
358 };
359
360
361 class OldFormatError : public std::runtime_error
362 {
363 public:
364         explicit OldFormatError (std::string s)
365                 : std::runtime_error (s)
366         {}
367 };
368
369
370 class KDMAsContentError : public std::runtime_error
371 {
372 public:
373         KDMAsContentError ();
374 };
375
376
377 class GLError : public std::runtime_error
378 {
379 public:
380         GLError (char const* last, int e);
381         GLError (char const* message);
382 };
383
384
385 /** @class CopyError
386  *  @brief An error which occurs when copying a DCP to a distribution drive.
387  */
388 class CopyError : public std::runtime_error
389 {
390 public:
391         CopyError (std::string s, boost::optional<int> n = boost::optional<int>());
392         virtual ~CopyError () throw () {}
393
394         std::string message () const {
395                 return _message;
396         }
397
398         boost::optional<int> number () const {
399                 return _number;
400         }
401
402 private:
403         std::string _message;
404         boost::optional<int> _number;
405 };
406
407
408 /** @class CommunicationFailedError
409  *  @brief Communcation between dcpomatic2_disk and _disk_writer failed somehow.
410  */
411 class CommunicationFailedError : public CopyError
412 {
413 public:
414         CommunicationFailedError ();
415 };
416
417
418 /** @class VerifyError
419  *  @brief An error which occurs when verifying a DCP that we copied to a distribution drive.
420  */
421 class VerifyError : public std::runtime_error
422 {
423 public:
424         VerifyError (std::string s, int n);
425         virtual ~VerifyError () throw () {}
426
427         std::string message () const {
428                 return _message;
429         }
430
431         int number () const {
432                 return _number;
433         }
434
435 private:
436         std::string _message;
437         int _number;
438 };
439
440
441 class PrivilegeError : public std::runtime_error
442 {
443 public:
444         explicit PrivilegeError (std::string s)
445                         : std::runtime_error (s)
446                 {}
447 };
448
449
450 #endif