2 Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
21 /** @file src/lib/exceptions.h
22 * @brief Our exceptions.
25 #ifndef DCPOMATIC_EXCEPTIONS_H
26 #define DCPOMATIC_EXCEPTIONS_H
28 #include "compose.hpp"
30 #include <libavutil/pixfmt.h>
32 #include <boost/filesystem.hpp>
33 #include <boost/optional.hpp>
37 /** @class DecodeError
38 * @brief A low-level problem with the decoder (possibly due to the nature
41 class DecodeError : public std::runtime_error
44 explicit DecodeError (std::string s)
45 : std::runtime_error (s)
48 explicit DecodeError (std::string function, std::string caller)
49 : std::runtime_error (String::compose("%1 failed in %2", function, caller))
52 explicit DecodeError (std::string function, std::string caller, int error)
53 : std::runtime_error (String::compose("%1 failed in %2 (%3)", function, caller, error))
57 class CryptoError : public std::runtime_error
60 explicit CryptoError (std::string s)
61 : std::runtime_error (s)
65 /** @class EncodeError
66 * @brief A low-level problem with an encoder.
68 class EncodeError : public std::runtime_error
71 explicit EncodeError (std::string s)
72 : std::runtime_error (s)
77 * @brief Parent class for file-related errors.
79 class FileError : public std::runtime_error
82 /** @param m Error message.
83 * @param f Name of the file that this exception concerns.
85 FileError (std::string m, boost::filesystem::path f)
86 : std::runtime_error (String::compose("%1 with %2", m, f.string()))
90 virtual ~FileError () throw () {}
92 /** @return name of the file that this exception concerns */
93 boost::filesystem::path file () const {
98 /** name of the file that this exception concerns */
99 boost::filesystem::path _file;
102 class JoinError : public std::runtime_error
105 explicit JoinError (std::string s)
106 : std::runtime_error (s)
110 /** @class OpenFileError.
111 * @brief Indicates that some error occurred when trying to open a file.
113 class OpenFileError : public FileError
122 /** @param f File that we were trying to open.
123 * @param error Code of error that occurred.
124 * @param mode Mode that we tried to open the file in.
126 OpenFileError (boost::filesystem::path f, int error, Mode mode);
129 class FileNotFoundError : public std::runtime_error
132 FileNotFoundError (boost::filesystem::path f);
133 virtual ~FileNotFoundError () throw () {}
135 /** @return name of the file that this exception concerns */
136 boost::filesystem::path file () const {
141 /** name of the file that this exception concerns */
142 boost::filesystem::path _file;
145 /** @class ReadFileError.
146 * @brief Indicates that some error occurred when trying to read from a file
148 class ReadFileError : public FileError
151 /** @param f File that we were trying to read from.
152 * @param e errno value, or 0.
154 ReadFileError (boost::filesystem::path f, int e = 0);
157 /** @class WriteFileError.
158 * @brief Indicates that some error occurred when trying to write to a file
160 class WriteFileError : public FileError
163 /** @param f File that we were trying to write to.
164 * @param e errno value, or 0.
166 WriteFileError (boost::filesystem::path f, int e);
169 /** @class SettingError.
170 * @brief Indicates that something is wrong with a setting.
172 class SettingError : public std::runtime_error
175 /** @param s Name of setting that was required.
178 SettingError (std::string s, std::string m)
179 : std::runtime_error (m)
183 virtual ~SettingError () throw () {}
185 /** @return name of setting in question */
186 std::string setting () const {
191 std::string _setting;
194 /** @class MissingSettingError.
195 * @brief Indicates that a Film is missing a setting that is required for some operation.
197 class MissingSettingError : public SettingError
200 /** @param s Name of setting that was required */
201 explicit MissingSettingError (std::string s);
204 /** @class BadSettingError
205 * @brief Indicates that a setting is bad in some way.
207 class BadSettingError : public SettingError
210 /** @param s Name of setting that is bad.
211 * @param m Error message.
213 BadSettingError (std::string s, std::string m)
214 : SettingError (s, m)
218 /** @class NetworkError
219 * @brief Indicates some problem with communication on the network.
221 class NetworkError : public std::runtime_error
224 explicit NetworkError (std::string s)
225 : std::runtime_error (s)
230 * @brief A problem with a KDM.
232 class KDMError : public std::runtime_error
235 KDMError (std::string s, std::string d);
236 ~KDMError () throw() {}
238 std::string summary () const {
242 std::string detail () const {
247 std::string _summary;
251 /** @class PixelFormatError
252 * @brief A problem with an unsupported pixel format.
254 class PixelFormatError : public std::runtime_error
257 PixelFormatError (std::string o, AVPixelFormat f);
260 /** @class TextSubtitleError
261 * @brief An error that occurs while parsing a TextSubtitleError file.
263 class TextSubtitleError : public FileError
266 TextSubtitleError (std::string, std::string, boost::filesystem::path);
269 class DCPError : public std::runtime_error
272 explicit DCPError (std::string s)
273 : std::runtime_error (s)
278 /** @class ProjectFolderError
279 * @brief An attempt has been made to read a DCP from a directory, but it looks
280 * like the directory actually contains a DCP-o-matic project.
282 class ProjectFolderError : public DCPError
285 /* Code which catches this exception will provide their own message */
286 ProjectFolderError ()
292 class InvalidSignerError : public std::runtime_error
295 InvalidSignerError ();
296 explicit InvalidSignerError (std::string reason);
299 class ProgrammingError : public std::runtime_error
302 ProgrammingError (std::string file, int line, std::string message = "");
305 class TextEncodingError : public std::runtime_error
308 explicit TextEncodingError (std::string s)
309 : std::runtime_error (s)
313 class MetadataError : public std::runtime_error
316 explicit MetadataError (std::string s)
317 : std::runtime_error (s)
321 class OldFormatError : public std::runtime_error
324 explicit OldFormatError (std::string s)
325 : std::runtime_error (s)
329 class KDMAsContentError : public std::runtime_error
332 KDMAsContentError ();
335 class GLError : public std::runtime_error
338 GLError (char const * last, int e);
342 * @brief An error which occurs when copying a DCP to a distribution drive.
344 class CopyError : public std::runtime_error
347 CopyError (std::string s, boost::optional<int> n = boost::optional<int>());
348 virtual ~CopyError () throw () {}
350 std::string message () const {
354 boost::optional<int> number () const {
359 std::string _message;
360 boost::optional<int> _number;
364 /** @class CommunicationFailedError
365 * @brief Communcation between dcpomatic2_disk and _disk_writer failed somehow.
367 class CommunicationFailedError : public CopyError
370 CommunicationFailedError ();
374 /** @class VerifyError
375 * @brief An error which occurs when verifying a DCP that we copied to a distribution drive.
377 class VerifyError : public std::runtime_error
380 VerifyError (std::string s, int n);
381 virtual ~VerifyError () throw () {}
383 std::string message () const {
387 int number () const {
392 std::string _message;
397 class PrivilegeError : public std::runtime_error
400 explicit PrivilegeError (std::string s)
401 : std::runtime_error (s)