Give a better error if a specified CPL does not exist.
authorCarl Hetherington <cth@carlh.net>
Sat, 17 Sep 2022 20:31:09 +0000 (22:31 +0200)
committerCarl Hetherington <cth@carlh.net>
Sat, 17 Sep 2022 20:31:09 +0000 (22:31 +0200)
src/lib/dcp_examiner.cc
src/lib/exceptions.h

index 8fa41a8a59d536dfe899d9cf0bd54a75a8dfebaa..5de8c89050caf391ed57848e64d433ed9414f7e9 100644 (file)
@@ -72,12 +72,12 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
        auto cpls = dcp::find_and_resolve_cpls (content->directories(), tolerant);
 
        if (content->cpl ()) {
-               /* Use the CPL that the content was using before */
-               for (auto i: cpls) {
-                       if (i->id() == content->cpl().get()) {
-                               cpl = i;
-                       }
+               /* Use the CPL that was specified, or that the content was using before */
+               auto iter = std::find_if(cpls.begin(), cpls.end(), [content](shared_ptr<dcp::CPL> cpl) { return cpl->id() == content->cpl().get(); });
+               if (iter == cpls.end()) {
+                       throw CPLNotFoundError(content->cpl().get());
                }
+               cpl = *iter;
        } else {
                /* Choose the CPL with the fewest unsatisfied references */
 
index 7c9509800ed3a40bf35f2cd88ce45755c44a03f8..618a03f4326510c8e532481ce899a7fb1dfcf18e 100644 (file)
@@ -335,6 +335,15 @@ public:
 };
 
 
+class CPLNotFoundError : public DCPError
+{
+public:
+       CPLNotFoundError(std::string id)
+               : DCPError(String::compose("CPL %1 not found", id))
+       {}
+};
+
+
 class InvalidSignerError : public std::runtime_error
 {
 public: