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)
257 : std::runtime_error (s)
263 * @brief A problem with a KDM.
265 class KDMError : public std::runtime_error
268 KDMError (std::string s, std::string d);
269 ~KDMError () throw() {}
271 std::string summary () const {
275 std::string detail () const {
280 std::string _summary;
285 /** @class PixelFormatError
286 * @brief A problem with an unsupported pixel format.
288 class PixelFormatError : public std::runtime_error
291 PixelFormatError (std::string o, AVPixelFormat f);
295 /** @class TextSubtitleError
296 * @brief An error that occurs while parsing a TextSubtitleError file.
298 class TextSubtitleError : public FileError
301 TextSubtitleError (std::string, std::string, boost::filesystem::path);
305 class DCPError : public std::runtime_error
308 explicit DCPError (std::string s)
309 : std::runtime_error (s)
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.
318 class ProjectFolderError : public DCPError
321 /* Code which catches this exception will provide their own message */
322 ProjectFolderError ()
328 class InvalidSignerError : public std::runtime_error
331 InvalidSignerError ();
332 explicit InvalidSignerError (std::string reason);
335 class ProgrammingError : public std::runtime_error
339 ProgrammingError (std::string file, int line, std::string message = "");
343 class TextEncodingError : public std::runtime_error
346 explicit TextEncodingError (std::string s)
347 : std::runtime_error (s)
352 class MetadataError : public std::runtime_error
355 explicit MetadataError (std::string s)
356 : std::runtime_error (s)
361 class OldFormatError : public std::runtime_error
364 explicit OldFormatError (std::string s)
365 : std::runtime_error (s)
370 class KDMAsContentError : public std::runtime_error
373 KDMAsContentError ();
377 class GLError : public std::runtime_error
380 GLError (char const * last, int e);
385 * @brief An error which occurs when copying a DCP to a distribution drive.
387 class CopyError : public std::runtime_error
390 CopyError (std::string s, boost::optional<int> n = boost::optional<int>());
391 virtual ~CopyError () throw () {}
393 std::string message () const {
397 boost::optional<int> number () const {
402 std::string _message;
403 boost::optional<int> _number;
407 /** @class CommunicationFailedError
408 * @brief Communcation between dcpomatic2_disk and _disk_writer failed somehow.
410 class CommunicationFailedError : public CopyError
413 CommunicationFailedError ();
417 /** @class VerifyError
418 * @brief An error which occurs when verifying a DCP that we copied to a distribution drive.
420 class VerifyError : public std::runtime_error
423 VerifyError (std::string s, int n);
424 virtual ~VerifyError () throw () {}
426 std::string message () const {
430 int number () const {
435 std::string _message;
440 class PrivilegeError : public std::runtime_error
443 explicit PrivilegeError (std::string s)
444 : std::runtime_error (s)