From fe9bbdf3f5223ee94cb51ba00ddab7f4a6ddb754 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 3 May 2014 15:05:33 +0100 Subject: [PATCH] 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 +++++++++++++++++++++- test/rewrite_subs.cc | 3 +-- tools/dcpdiff.cc | 12 ++++++------ tools/dcpinfo.cc | 6 +++--- 7 files changed, 62 insertions(+), 20 deletions(-) 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 */ diff --git a/test/rewrite_subs.cc b/test/rewrite_subs.cc index 0a2cd1ec..553c6291 100644 --- a/test/rewrite_subs.cc +++ b/test/rewrite_subs.cc @@ -42,8 +42,7 @@ main (int argc, char* argv[]) } DCP* dcp = new DCP (argv[1]); - list errors; - dcp->read (true, &errors); + dcp->read (true); list > cpls = dcp->cpls (); for (list >::iterator i = cpls.begin(); i != cpls.end(); ++i) { diff --git a/tools/dcpdiff.cc b/tools/dcpdiff.cc index e4225ebc..666fc1b2 100644 --- a/tools/dcpdiff.cc +++ b/tools/dcpdiff.cc @@ -105,10 +105,10 @@ main (int argc, char* argv[]) DCP* a = 0; try { a = new DCP (argv[optind]); - list errors; + list > errors; a->read (keep_going, &errors); - for (list::const_iterator i = errors.begin(); i != errors.end(); ++i) { - cerr << *i << "\n"; + for (list >::const_iterator i = errors.begin(); i != errors.end(); ++i) { + cerr << (*i)->what() << "\n"; } } catch (FileError& e) { cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n"; @@ -118,10 +118,10 @@ main (int argc, char* argv[]) DCP* b = 0; try { b = new DCP (argv[optind + 1]); - list errors; + list > errors; b->read (keep_going, &errors); - for (list::const_iterator i = errors.begin(); i != errors.end(); ++i) { - cerr << *i << "\n"; + for (list >::const_iterator i = errors.begin(); i != errors.end(); ++i) { + cerr << (*i)->what() << "\n"; } } catch (FileError& e) { cerr << "Could not read DCP " << argv[optind + 1] << "; " << e.what() << " " << e.filename() << "\n"; diff --git a/tools/dcpinfo.cc b/tools/dcpinfo.cc index c69de8a7..8f4c1b7d 100644 --- a/tools/dcpinfo.cc +++ b/tools/dcpinfo.cc @@ -148,7 +148,7 @@ main (int argc, char* argv[]) } DCP* dcp = 0; - list errors; + list > errors; try { dcp = new DCP (argv[optind]); dcp->read (keep_going, &errors); @@ -162,8 +162,8 @@ main (int argc, char* argv[]) cout << "DCP: " << boost::filesystem::path(argv[optind]).filename().string() << "\n"; - for (list::const_iterator i = errors.begin(); i != errors.end(); ++i) { - cerr << "Error: " << *i << "\n"; + for (list >::const_iterator i = errors.begin(); i != errors.end(); ++i) { + cerr << "Error: " << (*i)->what() << "\n"; } list > cpls = dcp->cpls (); -- 2.30.2