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 [%2", function, caller))
52 explicit DecodeError (std::string function, std::string caller, int error)
53 : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error))
57 class CryptoError : public std::runtime_error
60 explicit CryptoError (std::string s)
61 : std::runtime_error (s)
66 /** @class EncodeError
67 * @brief A low-level problem with an encoder.
69 class EncodeError : public std::runtime_error
72 explicit EncodeError (std::string s)
73 : std::runtime_error (s)
76 explicit EncodeError (std::string function, std::string caller)
77 : std::runtime_error (String::compose("%1 failed [%2]", function, caller))
80 explicit EncodeError (std::string function, std::string caller, int error)
81 : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error))
87 * @brief Parent class for file-related errors.
89 class FileError : public std::runtime_error
92 /** @param m Error message.
93 * @param f Name of the file that this exception concerns.
95 FileError (std::string m, boost::filesystem::path f)
96 : std::runtime_error (String::compose("%1 with %2", m, f.string()))
100 virtual ~FileError () throw () {}
102 /** @return name of the file that this exception concerns */
103 boost::filesystem::path file () const {
108 /** name of the file that this exception concerns */
109 boost::filesystem::path _file;
112 class JoinError : public std::runtime_error
115 explicit JoinError (std::string s)
116 : std::runtime_error (s)
120 /** @class OpenFileError.
121 * @brief Indicates that some error occurred when trying to open a file.
123 class OpenFileError : public FileError
132 /** @param f File that we were trying to open.
133 * @param error Code of error that occurred.
134 * @param mode Mode that we tried to open the file in.
136 OpenFileError (boost::filesystem::path f, int error, Mode mode);
139 class FileNotFoundError : public std::runtime_error
142 FileNotFoundError (boost::filesystem::path f);
143 virtual ~FileNotFoundError () throw () {}
145 /** @return name of the file that this exception concerns */
146 boost::filesystem::path file () const {
151 /** name of the file that this exception concerns */
152 boost::filesystem::path _file;
155 /** @class ReadFileError.
156 * @brief Indicates that some error occurred when trying to read from a file
158 class ReadFileError : public FileError
161 /** @param f File that we were trying to read from.
162 * @param e errno value, or 0.
164 ReadFileError (boost::filesystem::path f, int e = 0);
167 /** @class WriteFileError.
168 * @brief Indicates that some error occurred when trying to write to a file
170 class WriteFileError : public FileError
173 /** @param f File that we were trying to write to.
174 * @param e errno value, or 0.
176 WriteFileError (boost::filesystem::path f, int e);
179 /** @class SettingError.
180 * @brief Indicates that something is wrong with a setting.
182 class SettingError : public std::runtime_error
185 /** @param s Name of setting that was required.
188 SettingError (std::string s, std::string m)
189 : std::runtime_error (m)
193 virtual ~SettingError () throw () {}
195 /** @return name of setting in question */
196 std::string setting () const {
201 std::string _setting;
204 /** @class MissingSettingError.
205 * @brief Indicates that a Film is missing a setting that is required for some operation.
207 class MissingSettingError : public SettingError
210 /** @param s Name of setting that was required */
211 explicit MissingSettingError (std::string s);
214 /** @class BadSettingError
215 * @brief Indicates that a setting is bad in some way.
217 class BadSettingError : public SettingError
220 /** @param s Name of setting that is bad.
221 * @param m Error message.
223 BadSettingError (std::string s, std::string m)
224 : SettingError (s, m)
228 /** @class NetworkError
229 * @brief Indicates some problem with communication on the network.
231 class NetworkError : public std::runtime_error
234 explicit NetworkError (std::string s)
235 : std::runtime_error (s)
240 * @brief A problem with a KDM.
242 class KDMError : public std::runtime_error
245 KDMError (std::string s, std::string d);
246 ~KDMError () throw() {}
248 std::string summary () const {
252 std::string detail () const {
257 std::string _summary;
261 /** @class PixelFormatError
262 * @brief A problem with an unsupported pixel format.
264 class PixelFormatError : public std::runtime_error
267 PixelFormatError (std::string o, AVPixelFormat f);
270 /** @class TextSubtitleError
271 * @brief An error that occurs while parsing a TextSubtitleError file.
273 class TextSubtitleError : public FileError
276 TextSubtitleError (std::string, std::string, boost::filesystem::path);
279 class DCPError : public std::runtime_error
282 explicit DCPError (std::string s)
283 : std::runtime_error (s)
288 /** @class ProjectFolderError
289 * @brief An attempt has been made to read a DCP from a directory, but it looks
290 * like the directory actually contains a DCP-o-matic project.
292 class ProjectFolderError : public DCPError
295 /* Code which catches this exception will provide their own message */
296 ProjectFolderError ()
302 class InvalidSignerError : public std::runtime_error
305 InvalidSignerError ();
306 explicit InvalidSignerError (std::string reason);
309 class ProgrammingError : public std::runtime_error
312 ProgrammingError (std::string file, int line, std::string message = "");
315 class TextEncodingError : public std::runtime_error
318 explicit TextEncodingError (std::string s)
319 : std::runtime_error (s)
323 class MetadataError : public std::runtime_error
326 explicit MetadataError (std::string s)
327 : std::runtime_error (s)
331 class OldFormatError : public std::runtime_error
334 explicit OldFormatError (std::string s)
335 : std::runtime_error (s)
339 class KDMAsContentError : public std::runtime_error
342 KDMAsContentError ();
345 class GLError : public std::runtime_error
348 GLError (char const * last, int e);
352 * @brief An error which occurs when copying a DCP to a distribution drive.
354 class CopyError : public std::runtime_error
357 CopyError (std::string s, boost::optional<int> n = boost::optional<int>());
358 virtual ~CopyError () throw () {}
360 std::string message () const {
364 boost::optional<int> number () const {
369 std::string _message;
370 boost::optional<int> _number;
374 /** @class CommunicationFailedError
375 * @brief Communcation between dcpomatic2_disk and _disk_writer failed somehow.
377 class CommunicationFailedError : public CopyError
380 CommunicationFailedError ();
384 /** @class VerifyError
385 * @brief An error which occurs when verifying a DCP that we copied to a distribution drive.
387 class VerifyError : public std::runtime_error
390 VerifyError (std::string s, int n);
391 virtual ~VerifyError () throw () {}
393 std::string message () const {
397 int number () const {
402 std::string _message;
407 class PrivilegeError : public std::runtime_error
410 explicit PrivilegeError (std::string s)
411 : std::runtime_error (s)