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))
62 class CryptoError : public std::runtime_error
65 explicit CryptoError (std::string s)
66 : std::runtime_error (s)
71 /** @class EncodeError
72 * @brief A low-level problem with an encoder.
74 class EncodeError : public std::runtime_error
77 explicit EncodeError (std::string s)
78 : std::runtime_error (s)
81 explicit EncodeError (std::string function, std::string caller)
82 : std::runtime_error (String::compose("%1 failed [%2]", function, caller))
85 explicit EncodeError (std::string function, std::string caller, int error)
86 : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error))
92 * @brief Parent class for file-related errors.
94 class FileError : public std::runtime_error
97 /** @param m Error message.
98 * @param f Name of the file that this exception concerns.
100 FileError (std::string m, boost::filesystem::path f)
101 : std::runtime_error (String::compose("%1 with %2", m, f.string()))
105 virtual ~FileError () throw () {}
107 /** @return name of the file that this exception concerns */
108 boost::filesystem::path file () const {
113 /** name of the file that this exception concerns */
114 boost::filesystem::path _file;
118 class JoinError : public std::runtime_error
121 explicit JoinError (std::string s)
122 : std::runtime_error (s)
127 /** @class OpenFileError.
128 * @brief Indicates that some error occurred when trying to open a file.
130 class OpenFileError : public FileError
139 /** @param f File that we were trying to open.
140 * @param error Code of error that occurred.
141 * @param mode Mode that we tried to open the file in.
143 OpenFileError (boost::filesystem::path f, int error, Mode mode);
147 class FileNotFoundError : public std::runtime_error
150 FileNotFoundError (boost::filesystem::path f);
151 virtual ~FileNotFoundError () throw () {}
153 /** @return name of the file that this exception concerns */
154 boost::filesystem::path file () const {
159 /** name of the file that this exception concerns */
160 boost::filesystem::path _file;
164 /** @class ReadFileError.
165 * @brief Indicates that some error occurred when trying to read from a file
167 class ReadFileError : public FileError
170 /** @param f File that we were trying to read from.
171 * @param e errno value, or 0.
173 ReadFileError (boost::filesystem::path f, int e = 0);
177 /** @class WriteFileError.
178 * @brief Indicates that some error occurred when trying to write to a file
180 class WriteFileError : public FileError
183 /** @param f File that we were trying to write to.
184 * @param e errno value, or 0.
186 WriteFileError (boost::filesystem::path f, int e);
190 /** @class SettingError.
191 * @brief Indicates that something is wrong with a setting.
193 class SettingError : public std::runtime_error
196 /** @param s Name of setting that was required.
199 SettingError (std::string s, std::string m)
200 : std::runtime_error (m)
204 virtual ~SettingError () throw () {}
206 /** @return name of setting in question */
207 std::string setting () const {
212 std::string _setting;
216 /** @class MissingSettingError.
217 * @brief Indicates that a Film is missing a setting that is required for some operation.
219 class MissingSettingError : public SettingError
222 /** @param s Name of setting that was required */
223 explicit MissingSettingError (std::string s);
227 /** @class BadSettingError
228 * @brief Indicates that a setting is bad in some way.
230 class BadSettingError : public SettingError
233 /** @param s Name of setting that is bad.
234 * @param m Error message.
236 BadSettingError (std::string s, std::string m)
237 : SettingError (s, m)
242 /** @class NetworkError
243 * @brief Indicates some problem with communication on the network.
245 class NetworkError : public std::runtime_error
248 explicit NetworkError (std::string s)
249 : std::runtime_error (s)
255 * @brief A problem with a KDM.
257 class KDMError : public std::runtime_error
260 KDMError (std::string s, std::string d);
261 ~KDMError () throw() {}
263 std::string summary () const {
267 std::string detail () const {
272 std::string _summary;
277 /** @class PixelFormatError
278 * @brief A problem with an unsupported pixel format.
280 class PixelFormatError : public std::runtime_error
283 PixelFormatError (std::string o, AVPixelFormat f);
287 /** @class TextSubtitleError
288 * @brief An error that occurs while parsing a TextSubtitleError file.
290 class TextSubtitleError : public FileError
293 TextSubtitleError (std::string, std::string, boost::filesystem::path);
297 class DCPError : public std::runtime_error
300 explicit DCPError (std::string s)
301 : std::runtime_error (s)
306 /** @class ProjectFolderError
307 * @brief An attempt has been made to read a DCP from a directory, but it looks
308 * like the directory actually contains a DCP-o-matic project.
310 class ProjectFolderError : public DCPError
313 /* Code which catches this exception will provide their own message */
314 ProjectFolderError ()
320 class InvalidSignerError : public std::runtime_error
323 InvalidSignerError ();
324 explicit InvalidSignerError (std::string reason);
327 class ProgrammingError : public std::runtime_error
331 ProgrammingError (std::string file, int line, std::string message = "");
335 class TextEncodingError : public std::runtime_error
338 explicit TextEncodingError (std::string s)
339 : std::runtime_error (s)
344 class MetadataError : public std::runtime_error
347 explicit MetadataError (std::string s)
348 : std::runtime_error (s)
353 class OldFormatError : public std::runtime_error
356 explicit OldFormatError (std::string s)
357 : std::runtime_error (s)
362 class KDMAsContentError : public std::runtime_error
365 KDMAsContentError ();
369 class GLError : public std::runtime_error
372 GLError (char const * last, int e);
377 * @brief An error which occurs when copying a DCP to a distribution drive.
379 class CopyError : public std::runtime_error
382 CopyError (std::string s, boost::optional<int> n = boost::optional<int>());
383 virtual ~CopyError () throw () {}
385 std::string message () const {
389 boost::optional<int> number () const {
394 std::string _message;
395 boost::optional<int> _number;
399 /** @class CommunicationFailedError
400 * @brief Communcation between dcpomatic2_disk and _disk_writer failed somehow.
402 class CommunicationFailedError : public CopyError
405 CommunicationFailedError ();
409 /** @class VerifyError
410 * @brief An error which occurs when verifying a DCP that we copied to a distribution drive.
412 class VerifyError : public std::runtime_error
415 VerifyError (std::string s, int n);
416 virtual ~VerifyError () throw () {}
418 std::string message () const {
422 int number () const {
427 std::string _message;
432 class PrivilegeError : public std::runtime_error
435 explicit PrivilegeError (std::string s)
436 : std::runtime_error (s)