diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-05-03 15:05:33 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-05-03 15:05:33 +0100 |
| commit | fe9bbdf3f5223ee94cb51ba00ddab7f4a6ddb754 (patch) | |
| tree | 1d7ff4b95d3a65989c3cb136ae338e59ca5251b1 | |
| parent | 9f5a1507380c52338765477da7cbe378b68870d9 (diff) | |
Use exceptions to hold errors even in the keep_going case.
| -rw-r--r-- | src/dcp.cc | 12 | ||||
| -rw-r--r-- | src/dcp.h | 5 | ||||
| -rw-r--r-- | src/exceptions.cc | 22 | ||||
| -rw-r--r-- | src/exceptions.h | 22 | ||||
| -rw-r--r-- | test/rewrite_subs.cc | 3 | ||||
| -rw-r--r-- | tools/dcpdiff.cc | 12 | ||||
| -rw-r--r-- | tools/dcpinfo.cc | 6 |
7 files changed, 62 insertions, 20 deletions
@@ -69,17 +69,19 @@ DCP::DCP (boost::filesystem::path directory) } template<class T> void -survivable_error (bool keep_going, list<string>* errors, T const & e) +survivable_error (bool keep_going, list<shared_ptr<DCPReadError> >* errors, T const & e) { - if (keep_going && errors) { - errors->push_back (e.what ()); + if (keep_going) { + if (errors) { + errors->push_back (shared_ptr<T> (new T (e))); + } } else { throw e; } } void -DCP::read (bool keep_going, list<string>* errors) +DCP::read (bool keep_going, list<shared_ptr<DCPReadError> >* errors) { /* Read the ASSETMAP */ @@ -112,7 +114,7 @@ DCP::read (bool keep_going, list<string>* 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; } @@ -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<std::string>* errors = 0); + void read (bool keep_going = false, std::list<boost::shared_ptr<DCPReadError> >* 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<string> errors; - dcp->read (true, &errors); + dcp->read (true); list<shared_ptr<CPL> > cpls = dcp->cpls (); for (list<boost::shared_ptr<CPL> >::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<string> errors; + list<shared_ptr<DCPReadError> > errors; a->read (keep_going, &errors); - for (list<string>::const_iterator i = errors.begin(); i != errors.end(); ++i) { - cerr << *i << "\n"; + for (list<shared_ptr<DCPReadError> >::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<string> errors; + list<shared_ptr<DCPReadError> > errors; b->read (keep_going, &errors); - for (list<string>::const_iterator i = errors.begin(); i != errors.end(); ++i) { - cerr << *i << "\n"; + for (list<shared_ptr<DCPReadError> >::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<string> errors; + list<shared_ptr<DCPReadError> > 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<string>::const_iterator i = errors.begin(); i != errors.end(); ++i) { - cerr << "Error: " << *i << "\n"; + for (list<shared_ptr<DCPReadError> >::const_iterator i = errors.begin(); i != errors.end(); ++i) { + cerr << "Error: " << (*i)->what() << "\n"; } list<shared_ptr<CPL> > cpls = dcp->cpls (); |
