Throw exceptions with badly-formed XML when reading a DCP; preserve detail in DCPRead...
authorCarl Hetherington <cth@carlh.net>
Sun, 25 Feb 2018 00:39:01 +0000 (00:39 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 25 Feb 2018 00:39:01 +0000 (00:39 +0000)
src/dcp.cc
src/exceptions.cc
src/exceptions.h

index fc02fe9dbe2a940ed1218807350ce4b6a81a565f..7b4f9bdaac3efe05129877c465b3f715d3835b6d 100644 (file)
@@ -169,7 +169,7 @@ DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mx
                                p->parse_file (path.string());
                        } catch (std::exception& e) {
                                delete p;
-                               continue;
+                               throw DCPReadError(String::compose("XML error in %1", path.string()), e.what());
                        }
 
                        string const root = p->get_document()->get_root_node()->get_name ();
index 71771b1c1248a8d80b595de17a46eb7f04fdd946..1ded4483485649d97e57200d549a45b20d144cf9 100644 (file)
@@ -108,3 +108,11 @@ CertificateChainError::CertificateChainError (std::string message)
 {
 
 }
+
+DCPReadError::DCPReadError (string message, string detail)
+       : runtime_error(String::compose("%1 (%2)", message, detail))
+       , _message(message)
+       , _detail(detail)
+{
+
+}
index f187df1c820f62e508c4afdc05217e54176450dd..3d80b635e8bdab4705ee56a3e8c8424047b5effd 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
@@ -35,6 +35,7 @@
 #define LIBDCP_EXCEPTIONS_H
 
 #include <boost/filesystem.hpp>
+#include <boost/optional.hpp>
 
 /** @file  src/exceptions.h
  *  @brief Exceptions thrown by libdcp.
@@ -97,8 +98,22 @@ class DCPReadError : public std::runtime_error
 {
 public:
        explicit DCPReadError (std::string message)
-               : std::runtime_error (message)
+               : std::runtime_error(message)
        {}
+
+       DCPReadError (std::string message, std::string detail);
+
+       std::string message () const {
+               return _message;
+       }
+
+       boost::optional<std::string> detail () const {
+               return _detail;
+       }
+
+private:
+       std::string _message;
+       boost::optional<std::string> _detail;
 };
 
 /** @class MissingAssetError