X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fexceptions.h;h=38452ffc02b7c0867596cb55787a77c29eeafc01;hb=2b9bdd0f97172514efe265a517653c4e49d89f55;hp=6bad7c9245bbb8ae833e4202841a08a3ccfc2896;hpb=9525e7726e4d488f193957d4fcf1cc1725581ae8;p=dcpomatic.git diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index 6bad7c924..80d4801da 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -1,109 +1,136 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ -#ifndef DCPOMATIC_EXCEPTIONS_H -#define DCPOMATIC_EXCEPTIONS_H -/** @file src/exceptions.h +/** @file src/lib/exceptions.h * @brief Our exceptions. */ -#include -#include -#include -#include + +#ifndef DCPOMATIC_EXCEPTIONS_H +#define DCPOMATIC_EXCEPTIONS_H + + +#include "compose.hpp" extern "C" { #include } +#include +#include +#include +#include + -/** @class StringError - * @brief A parent class for exceptions using messages held in a std::string +/** @class DecodeError + * @brief A low-level problem with the decoder (possibly due to the nature + * of a source file). */ -class StringError : public std::exception +class DecodeError : public std::runtime_error { public: - /** @param w Error message */ - StringError (std::string w) { - _what = w; - } + explicit DecodeError (std::string s) + : std::runtime_error (s) + {} - virtual ~StringError () throw () {} + DecodeError (std::string function, std::string caller) + : std::runtime_error (String::compose("%1 failed [%2]", function, caller)) + {} - /** @return error message */ - char const * what () const throw () { - return _what.c_str (); - } + DecodeError (std::string function, std::string caller, int error) + : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error)) + {} -protected: - /** error message */ - std::string _what; + DecodeError (std::string function, std::string caller, boost::filesystem::path file) + : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, file.string())) + {} + + DecodeError (std::string function, std::string caller, int error, boost::filesystem::path file) + : std::runtime_error (String::compose("%1 failed [%2] (%3) (%4)", function, caller, error, file.string())) + {} }; -/** @class DecodeError - * @brief A low-level problem with the decoder (possibly due to the nature - * of a source file). - */ -class DecodeError : public StringError + +class CryptoError : public std::runtime_error { public: - DecodeError (std::string s) - : StringError (s) + explicit CryptoError (std::string s) + : std::runtime_error (s) {} }; + /** @class EncodeError * @brief A low-level problem with an encoder. */ -class EncodeError : public StringError +class EncodeError : public std::runtime_error { public: - EncodeError (std::string s) - : StringError (s) + explicit EncodeError (std::string s) + : std::runtime_error (s) + {} + + explicit EncodeError (std::string function, std::string caller) + : std::runtime_error (String::compose("%1 failed [%2]", function, caller)) + {} + + explicit EncodeError (std::string function, std::string caller, int error) + : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error)) {} }; + /** @class FileError. * @brief Parent class for file-related errors. */ -class FileError : public StringError +class FileError : public std::runtime_error { public: /** @param m Error message. * @param f Name of the file that this exception concerns. */ - FileError (std::string m, std::string f) - : StringError (m) + FileError (std::string m, boost::filesystem::path f) + : std::runtime_error (String::compose("%1 with %2", m, f.string())) , _file (f) {} virtual ~FileError () throw () {} /** @return name of the file that this exception concerns */ - std::string file () const { + boost::filesystem::path file () const { return _file; } private: /** name of the file that this exception concerns */ - std::string _file; + boost::filesystem::path _file; +}; + + +class JoinError : public std::runtime_error +{ +public: + explicit JoinError (std::string s) + : std::runtime_error (s) + {} }; - + /** @class OpenFileError. * @brief Indicates that some error occurred when trying to open a file. @@ -111,19 +138,34 @@ private: class OpenFileError : public FileError { public: - /** @param f File that we were trying to open */ - /* XXX: should be boost::filesystem::path */ - OpenFileError (std::string f); + enum Mode { + READ, + WRITE, + READ_WRITE + }; + + /** @param f File that we were trying to open. + * @param error Code of error that occurred. + * @param mode Mode that we tried to open the file in. + */ + OpenFileError (boost::filesystem::path f, int error, Mode mode); }; -/** @class CreateFileError. - * @brief Indicates that some error occurred when trying to create a file. - */ -class CreateFileError : public FileError + +class FileNotFoundError : public std::runtime_error { public: - /** @param f File that we were trying to create */ - CreateFileError (std::string f); + FileNotFoundError (boost::filesystem::path f); + virtual ~FileNotFoundError () throw () {} + + /** @return name of the file that this exception concerns */ + boost::filesystem::path file () const { + return _file; + } + +private: + /** name of the file that this exception concerns */ + boost::filesystem::path _file; }; @@ -136,9 +178,10 @@ public: /** @param f File that we were trying to read from. * @param e errno value, or 0. */ - ReadFileError (std::string f, int e = 0); + ReadFileError (boost::filesystem::path f, int e = 0); }; + /** @class WriteFileError. * @brief Indicates that some error occurred when trying to write to a file */ @@ -148,20 +191,21 @@ public: /** @param f File that we were trying to write to. * @param e errno value, or 0. */ - WriteFileError (std::string f, int e); + WriteFileError (boost::filesystem::path f, int e); }; + /** @class SettingError. * @brief Indicates that something is wrong with a setting. */ -class SettingError : public StringError +class SettingError : public std::runtime_error { public: /** @param s Name of setting that was required. * @param m Message. */ SettingError (std::string s, std::string m) - : StringError (m) + : std::runtime_error (m) , _setting (s) {} @@ -176,6 +220,7 @@ private: std::string _setting; }; + /** @class MissingSettingError. * @brief Indicates that a Film is missing a setting that is required for some operation. */ @@ -183,63 +228,247 @@ class MissingSettingError : public SettingError { public: /** @param s Name of setting that was required */ - MissingSettingError (std::string s); + explicit MissingSettingError (std::string s); }; + /** @class BadSettingError * @brief Indicates that a setting is bad in some way. */ class BadSettingError : public SettingError { public: - /** @param s Name of setting that is bad */ + /** @param s Name of setting that is bad. + * @param m Error message. + */ BadSettingError (std::string s, std::string m) : SettingError (s, m) {} }; -/** @class NetworkError. + +/** @class NetworkError * @brief Indicates some problem with communication on the network. */ -class NetworkError : public StringError +class NetworkError : public std::runtime_error { public: - NetworkError (std::string s) - : StringError (s) - {} + explicit NetworkError (std::string s, boost::optional d = boost::optional()); + + std::string summary () const { + return _summary; + } + + boost::optional detail () const { + return _detail; + } + +private: + std::string _summary; + boost::optional _detail; }; -class PixelFormatError : public StringError + +/** @class KDMError + * @brief A problem with a KDM. + */ +class KDMError : public std::runtime_error +{ +public: + KDMError (std::string s, std::string d); + ~KDMError () throw() {} + + std::string summary () const { + return _summary; + } + + std::string detail () const { + return _detail; + } + +private: + std::string _summary; + std::string _detail; +}; + + +/** @class PixelFormatError + * @brief A problem with an unsupported pixel format. + */ +class PixelFormatError : public std::runtime_error { public: PixelFormatError (std::string o, AVPixelFormat f); }; -class ExceptionStore + +/** @class TextSubtitleError + * @brief An error that occurs while parsing a TextSubtitleError file. + */ +class TextSubtitleError : public FileError +{ +public: + TextSubtitleError (std::string, std::string, boost::filesystem::path); +}; + + +class DCPError : public std::runtime_error +{ +public: + explicit DCPError (std::string s) + : std::runtime_error (s) + {} +}; + + +/** @class ProjectFolderError + * @brief An attempt has been made to read a DCP from a directory, but it looks + * like the directory actually contains a DCP-o-matic project. + */ +class ProjectFolderError : public DCPError +{ +public: + /* Code which catches this exception will provide their own message */ + ProjectFolderError () + : DCPError ("dummy") + {} +}; + + +class CPLNotFoundError : public DCPError { public: - bool thrown () const { - boost::mutex::scoped_lock lm (_mutex); - return _exception; + CPLNotFoundError(std::string id) + : DCPError(String::compose("CPL %1 not found", id)) + {} +}; + + +class InvalidSignerError : public std::runtime_error +{ +public: + InvalidSignerError (); + explicit InvalidSignerError (std::string reason); +}; + + +class ProgrammingError : public std::runtime_error +{ +public: + ProgrammingError (std::string file, int line, std::string message = ""); +}; + + +class TextEncodingError : public std::runtime_error +{ +public: + explicit TextEncodingError (std::string s) + : std::runtime_error (s) + {} +}; + + +class MetadataError : public std::runtime_error +{ +public: + explicit MetadataError (std::string s) + : std::runtime_error (s) + {} +}; + + +class OldFormatError : public std::runtime_error +{ +public: + explicit OldFormatError (std::string s) + : std::runtime_error (s) + {} +}; + + +class KDMAsContentError : public std::runtime_error +{ +public: + KDMAsContentError (); +}; + + +class GLError : public std::runtime_error +{ +public: + GLError (char const* last, int e); + GLError (char const* message); +}; + + +/** @class CopyError + * @brief An error which occurs when copying a DCP to a distribution drive. + */ +class CopyError : public std::runtime_error +{ +public: + CopyError (std::string s, boost::optional ext4_error = boost::optional(), boost::optional platform_error = boost::optional()); + virtual ~CopyError () throw () {} + + std::string message () const { + return _message; + } + + boost::optional ext4_number() const { + return _ext4_number; + } + + boost::optional platform_number() const { + return _platform_number; } - - void rethrow () { - boost::mutex::scoped_lock lm (_mutex); - boost::rethrow_exception (_exception); + +private: + std::string _message; + boost::optional _ext4_number; + boost::optional _platform_number; +}; + + +/** @class CommunicationFailedError + * @brief Communication between dcpomatic2_disk and _disk_writer failed somehow. + */ +class CommunicationFailedError : public CopyError +{ +public: + CommunicationFailedError (); +}; + + +/** @class VerifyError + * @brief An error which occurs when verifying a DCP that we copied to a distribution drive. + */ +class VerifyError : public std::runtime_error +{ +public: + VerifyError (std::string s, int n); + virtual ~VerifyError () throw () {} + + std::string message () const { + return _message; } -protected: - - void store_current () { - boost::mutex::scoped_lock lm (_mutex); - _exception = boost::current_exception (); + int number () const { + return _number; } private: - boost::exception_ptr _exception; - mutable boost::mutex _mutex; + std::string _message; + int _number; +}; + + +class PrivilegeError : public std::runtime_error +{ +public: + explicit PrivilegeError (std::string s) + : std::runtime_error (s) + {} }; - #endif