From fe9bbdf3f5223ee94cb51ba00ddab7f4a6ddb754 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 3 May 2014 15:05:33 +0100 Subject: Use exceptions to hold errors even in the keep_going case. --- src/dcp.cc | 12 +++++++----- src/dcp.h | 5 +++-- src/exceptions.cc | 22 +++++++++++++++++++++- src/exceptions.h | 22 +++++++++++++++++++++- 4 files changed, 52 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/dcp.cc b/src/dcp.cc index c0d148c5..dc0ffeaa 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -69,17 +69,19 @@ DCP::DCP (boost::filesystem::path directory) } template void -survivable_error (bool keep_going, list* errors, T const & e) +survivable_error (bool keep_going, list >* errors, T const & e) { - if (keep_going && errors) { - errors->push_back (e.what ()); + if (keep_going) { + if (errors) { + errors->push_back (shared_ptr (new T (e))); + } } else { throw e; } } void -DCP::read (bool keep_going, list* errors) +DCP::read (bool keep_going, list >* errors) { /* Read the ASSETMAP */ @@ -112,7 +114,7 @@ DCP::read (bool keep_going, list* errors) boost::filesystem::path path = _directory / i->second; if (!boost::filesystem::exists (path)) { - survivable_error (keep_going, errors, FileError ("file not found", path, -1)); + survivable_error (keep_going, errors, MissingAssetError (path)); continue; } diff --git a/src/dcp.h b/src/dcp.h index 48b2df3c..66486ca0 100644 --- a/src/dcp.h +++ b/src/dcp.h @@ -48,6 +48,7 @@ class XMLMetadata; class Signer; class DecryptedKDM; class Asset; +class DCPReadError; namespace parse { class AssetMap; @@ -70,9 +71,9 @@ public: /** Read the DCP's structure into this object. * @param keep_going true to try to keep going in the face of (some) errors. - * @param notes List of errors that will be added to if keep_going is true. + * @param errors List of errors that will be added to if keep_going is true. */ - void read (bool keep_going = false, std::list* errors = 0); + void read (bool keep_going = false, std::list >* errors = 0); /** Compare this DCP with another, according to various options. * @param other DCP to compare this one to. diff --git a/src/exceptions.cc b/src/exceptions.cc index 48da4fcd..28846e16 100644 --- a/src/exceptions.cc +++ b/src/exceptions.cc @@ -47,4 +47,24 @@ TimeFormatError::TimeFormatError (string bad_time) } - +MissingAssetError::MissingAssetError (boost::filesystem::path path, AssetType type) + : _path (path) + , _type (type) +{ + string type_name; + switch (_type) { + case MAIN_PICTURE: + type_name = " for main picture"; + break; + case MAIN_SOUND: + type_name = " for main sound"; + break; + case MAIN_SUBTITLE: + type_name = " for main subtitle"; + break; + case UNKNOWN: + break; + } + + _message = String::compose ("Missing asset %1%2", path.string(), type_name); +} diff --git a/src/exceptions.h b/src/exceptions.h index 7446e352..43ddab02 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -105,11 +105,31 @@ public: return _message.c_str (); } -private: +protected: + DCPReadError () {} + /** error message */ std::string _message; }; +class MissingAssetError : public DCPReadError +{ +public: + enum AssetType { + MAIN_PICTURE, + MAIN_SOUND, + MAIN_SUBTITLE, + UNKNOWN + }; + + MissingAssetError (boost::filesystem::path, AssetType = UNKNOWN); + ~MissingAssetError () throw () {} + +private: + boost::filesystem::path _path; + AssetType _type; +}; + /** @class XMLError * @brief An XML error */ -- cgit v1.2.3