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