2 Copyright (C) 2012-2021 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/>.
22 /** @file src/lib/exceptions.h
23 * @brief Our exceptions.
27 #ifndef DCPOMATIC_EXCEPTIONS_H
28 #define DCPOMATIC_EXCEPTIONS_H
31 #include "compose.hpp"
33 #include <libavutil/pixfmt.h>
35 #include <boost/filesystem.hpp>
36 #include <boost/optional.hpp>
41 /** @class DecodeError
42 * @brief A low-level problem with the decoder (possibly due to the nature
45 class DecodeError : public std::runtime_error
48 explicit DecodeError (std::string s)
49 : std::runtime_error (s)
52 DecodeError (std::string function, std::string caller)
53 : std::runtime_error (String::compose("%1 failed [%2]", function, caller))
56 DecodeError (std::string function, std::string caller, int error)
57 : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error))
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()))
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()))
70 class CryptoError : public std::runtime_error
73 explicit CryptoError (std::string s)
74 : std::runtime_error (s)
79 /** @class EncodeError
80 * @brief A low-level problem with an encoder.
82 class EncodeError : public std::runtime_error
85 explicit EncodeError (std::string s)
86 : std::runtime_error (s)
89 explicit EncodeError (std::string function, std::string caller)
90 : std::runtime_error (String::compose("%1 failed [%2]", function, caller))
93 explicit EncodeError (std::string function, std::string caller, int error)
94 : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error))
100 * @brief Parent class for file-related errors.
102 class FileError : public std::runtime_error
105 /** @param m Error message.
106 * @param f Name of the file that this exception concerns.
108 FileError (std::string m, boost::filesystem::path f)
109 : std::runtime_error (String::compose("%1 with %2", m, f.string()))
113 virtual ~FileError () throw () {}
115 /** @return name of the file that this exception concerns */
116 boost::filesystem::path file () const {
121 /** name of the file that this exception concerns */
122 boost::filesystem::path _file;
126 class JoinError : public std::runtime_error
129 explicit JoinError (std::string s)
130 : std::runtime_error (s)
135 /** @class OpenFileError.
136 * @brief Indicates that some error occurred when trying to open a file.
138 class OpenFileError : public FileError
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.
151 OpenFileError (boost::filesystem::path f, int error, Mode mode);
155 class FileNotFoundError : public std::runtime_error
158 FileNotFoundError (boost::filesystem::path f);
159 virtual ~FileNotFoundError () throw () {}
161 /** @return name of the file that this exception concerns */
162 boost::filesystem::path file () const {
167 /** name of the file that this exception concerns */
168 boost::filesystem::path _file;
172 /** @class ReadFileError.
173 * @brief Indicates that some error occurred when trying to read from a file
175 class ReadFileError : public FileError
178 /** @param f File that we were trying to read from.
179 * @param e errno value, or 0.
181 ReadFileError (boost::filesystem::path f, int e = 0);
185 /** @class WriteFileError.
186 * @brief Indicates that some error occurred when trying to write to a file
188 class WriteFileError : public FileError
191 /** @param f File that we were trying to write to.
192 * @param e errno value, or 0.
194 WriteFileError (boost::filesystem::path f, int e);
198 /** @class SettingError.
199 * @brief Indicates that something is wrong with a setting.
201 class SettingError : public std::runtime_error
204 /** @param s Name of setting that was required.
207 SettingError (std::string s, std::string m)
208 : std::runtime_error (m)
212 virtual ~SettingError () throw () {}
214 /** @return name of setting in question */
215 std::string setting () const {
220 std::string _setting;
224 /** @class MissingSettingError.
225 * @brief Indicates that a Film is missing a setting that is required for some operation.
227 class MissingSettingError : public SettingError
230 /** @param s Name of setting that was required */
231 explicit MissingSettingError (std::string s);
235 /** @class BadSettingError
236 * @brief Indicates that a setting is bad in some way.
238 class BadSettingError : public SettingError
241 /** @param s Name of setting that is bad.
242 * @param m Error message.
244 BadSettingError (std::string s, std::string m)
245 : SettingError (s, m)
250 /** @class NetworkError
251 * @brief Indicates some problem with communication on the network.
253 class NetworkError : public std::runtime_error
256 explicit NetworkError (std::string s, boost::optional<std::string> d = boost::optional<std::string>());
258 std::string summary () const {
262 boost::optional<std::string> detail () const {
267 std::string _summary;
268 boost::optional<std::string> _detail;
273 * @brief A problem with a KDM.
275 class KDMError : public std::runtime_error
278 KDMError (std::string s, std::string d);
279 ~KDMError () throw() {}
281 std::string summary () const {
285 std::string detail () const {
290 std::string _summary;
295 /** @class PixelFormatError
296 * @brief A problem with an unsupported pixel format.
298 class PixelFormatError : public std::runtime_error
301 PixelFormatError (std::string o, AVPixelFormat f);
305 /** @class TextSubtitleError
306 * @brief An error that occurs while parsing a TextSubtitleError file.
308 class TextSubtitleError : public FileError
311 TextSubtitleError (std::string, std::string, boost::filesystem::path);
315 class DCPError : public std::runtime_error
318 explicit DCPError (std::string s)
319 : std::runtime_error (s)
324 /** @class ProjectFolderError
325 * @brief An attempt has been made to read a DCP from a directory, but it looks
326 * like the directory actually contains a DCP-o-matic project.
328 class ProjectFolderError : public DCPError
331 /* Code which catches this exception will provide their own message */
332 ProjectFolderError ()
338 class CPLNotFoundError : public DCPError
341 CPLNotFoundError(std::string id)
342 : DCPError(String::compose("CPL %1 not found", id))
347 class InvalidSignerError : public std::runtime_error
350 InvalidSignerError ();
351 explicit InvalidSignerError (std::string reason);
355 class ProgrammingError : public std::runtime_error
358 ProgrammingError (std::string file, int line, std::string message = "");
362 class TextEncodingError : public std::runtime_error
365 explicit TextEncodingError (std::string s)
366 : std::runtime_error (s)
371 class MetadataError : public std::runtime_error
374 explicit MetadataError (std::string s)
375 : std::runtime_error (s)
380 class OldFormatError : public std::runtime_error
383 explicit OldFormatError (std::string s)
384 : std::runtime_error (s)
389 class KDMAsContentError : public std::runtime_error
392 KDMAsContentError ();
396 class GLError : public std::runtime_error
399 GLError (char const* last, int e);
400 GLError (char const* message);
405 * @brief An error which occurs when copying a DCP to a distribution drive.
407 class CopyError : public std::runtime_error
410 CopyError (std::string s, boost::optional<int> ext4_error = boost::optional<int>(), boost::optional<int> platform_error = boost::optional<int>());
411 virtual ~CopyError () throw () {}
413 std::string message () const {
417 boost::optional<int> ext4_number() const {
421 boost::optional<int> platform_number() const {
422 return _platform_number;
426 std::string _message;
427 boost::optional<int> _ext4_number;
428 boost::optional<int> _platform_number;
432 /** @class CommunicationFailedError
433 * @brief Communication between dcpomatic2_disk and _disk_writer failed somehow.
435 class CommunicationFailedError : public CopyError
438 CommunicationFailedError ();
442 /** @class VerifyError
443 * @brief An error which occurs when verifying a DCP that we copied to a distribution drive.
445 class VerifyError : public std::runtime_error
448 VerifyError (std::string s, int n);
449 virtual ~VerifyError () throw () {}
451 std::string message () const {
455 int number () const {
460 std::string _message;
465 class PrivilegeError : public std::runtime_error
468 explicit PrivilegeError (std::string s)
469 : std::runtime_error (s)