Make FileError say what path the problem was with.
[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 <stdexcept>
34 #include <cstring>
35
36 /** @class DecodeError
37  *  @brief A low-level problem with the decoder (possibly due to the nature
38  *  of a source file).
39  */
40 class DecodeError : public std::runtime_error
41 {
42 public:
43         explicit DecodeError (std::string s)
44                 : std::runtime_error (s)
45         {}
46 };
47
48 class CryptoError : public std::runtime_error
49 {
50 public:
51         explicit CryptoError (std::string s)
52                 : std::runtime_error (s)
53         {}
54 };
55
56 /** @class EncodeError
57  *  @brief A low-level problem with an encoder.
58  */
59 class EncodeError : public std::runtime_error
60 {
61 public:
62         explicit EncodeError (std::string s)
63                 : std::runtime_error (s)
64         {}
65 };
66
67 /** @class FileError.
68  *  @brief Parent class for file-related errors.
69  */
70 class FileError : public std::runtime_error
71 {
72 public:
73         /** @param m Error message.
74          *  @param f Name of the file that this exception concerns.
75          */
76         FileError (std::string m, boost::filesystem::path f)
77                 : std::runtime_error (String::compose("%1 with %2", m, f.string()))
78                 , _file (f)
79         {}
80
81         virtual ~FileError () throw () {}
82
83         /** @return name of the file that this exception concerns */
84         boost::filesystem::path file () const {
85                 return _file;
86         }
87
88 private:
89         /** name of the file that this exception concerns */
90         boost::filesystem::path _file;
91 };
92
93 class JoinError : public std::runtime_error
94 {
95 public:
96         explicit JoinError (std::string s)
97                 : std::runtime_error (s)
98         {}
99 };
100
101 /** @class OpenFileError.
102  *  @brief Indicates that some error occurred when trying to open a file.
103  */
104 class OpenFileError : public FileError
105 {
106 public:
107         enum Mode {
108                 READ,
109                 WRITE,
110                 READ_WRITE
111         };
112
113         /** @param f File that we were trying to open.
114          *  @param error Code of error that occurred.
115          *  @param mode Mode that we tried to open the file in.
116          */
117         OpenFileError (boost::filesystem::path f, int error, Mode mode);
118 };
119
120 /** @class ReadFileError.
121  *  @brief Indicates that some error occurred when trying to read from a file
122  */
123 class ReadFileError : public FileError
124 {
125 public:
126         /** @param f File that we were trying to read from.
127          *  @param e errno value, or 0.
128          */
129         ReadFileError (boost::filesystem::path f, int e = 0);
130 };
131
132 /** @class WriteFileError.
133  *  @brief Indicates that some error occurred when trying to write to a file
134  */
135 class WriteFileError : public FileError
136 {
137 public:
138         /** @param f File that we were trying to write to.
139          *  @param e errno value, or 0.
140          */
141         WriteFileError (boost::filesystem::path f, int e);
142 };
143
144 /** @class SettingError.
145  *  @brief Indicates that something is wrong with a setting.
146  */
147 class SettingError : public std::runtime_error
148 {
149 public:
150         /** @param s Name of setting that was required.
151          *  @param m Message.
152          */
153         SettingError (std::string s, std::string m)
154                 : std::runtime_error (m)
155                 , _setting (s)
156         {}
157
158         virtual ~SettingError () throw () {}
159
160         /** @return name of setting in question */
161         std::string setting () const {
162                 return _setting;
163         }
164
165 private:
166         std::string _setting;
167 };
168
169 /** @class MissingSettingError.
170  *  @brief Indicates that a Film is missing a setting that is required for some operation.
171  */
172 class MissingSettingError : public SettingError
173 {
174 public:
175         /** @param s Name of setting that was required */
176         explicit MissingSettingError (std::string s);
177 };
178
179 /** @class BadSettingError
180  *  @brief Indicates that a setting is bad in some way.
181  */
182 class BadSettingError : public SettingError
183 {
184 public:
185         /** @param s Name of setting that is bad.
186          *  @param m Error message.
187          */
188         BadSettingError (std::string s, std::string m)
189                 : SettingError (s, m)
190         {}
191 };
192
193 /** @class NetworkError
194  *  @brief Indicates some problem with communication on the network.
195  */
196 class NetworkError : public std::runtime_error
197 {
198 public:
199         explicit NetworkError (std::string s)
200                 : std::runtime_error (s)
201         {}
202 };
203
204 /** @class KDMError
205  *  @brief A problem with a KDM.
206  */
207 class KDMError : public std::runtime_error
208 {
209 public:
210         KDMError (std::string s, std::string d);
211         ~KDMError () throw() {}
212
213         std::string summary () const {
214                 return _summary;
215         }
216
217         std::string detail () const {
218                 return _detail;
219         }
220
221 private:
222         std::string _summary;
223         std::string _detail;
224 };
225
226 /** @class PixelFormatError
227  *  @brief A problem with an unsupported pixel format.
228  */
229 class PixelFormatError : public std::runtime_error
230 {
231 public:
232         PixelFormatError (std::string o, AVPixelFormat f);
233 };
234
235 /** @class TextSubtitleError
236  *  @brief An error that occurs while parsing a TextSubtitleError file.
237  */
238 class TextSubtitleError : public FileError
239 {
240 public:
241         TextSubtitleError (std::string, std::string, boost::filesystem::path);
242 };
243
244 class DCPError : public std::runtime_error
245 {
246 public:
247         explicit DCPError (std::string s)
248                 : std::runtime_error (s)
249         {}
250 };
251
252 class InvalidSignerError : public std::runtime_error
253 {
254 public:
255         InvalidSignerError ();
256         explicit InvalidSignerError (std::string reason);
257 };
258
259 class ProgrammingError : public std::runtime_error
260 {
261 public:
262         ProgrammingError (std::string file, int line, std::string message = "");
263 };
264
265 class TextEncodingError : public std::runtime_error
266 {
267 public:
268         explicit TextEncodingError (std::string s)
269                 : std::runtime_error (s)
270         {}
271 };
272
273 class MetadataError : public std::runtime_error
274 {
275 public:
276         explicit MetadataError (std::string s)
277                 : std::runtime_error (s)
278         {}
279 };
280
281 class OldFormatError : public std::runtime_error
282 {
283 public:
284         explicit OldFormatError (std::string s)
285                 : std::runtime_error (s)
286         {}
287 };
288
289 class KDMAsContentError : public std::runtime_error
290 {
291 public:
292         KDMAsContentError ();
293 };
294
295 #endif