From f5aef1b391e8c112543a6cebe50e8397b1daf3ca Mon Sep 17 00:00:00 2001
From: jvoisin <julien.voisin@dustri.org>
Date: Sun, 15 Dec 2019 09:04:51 -0800
Subject: [PATCH] Improve the reliability of Exiftool-base parsers

---
 libmat2/exiftool.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/libmat2/exiftool.py b/libmat2/exiftool.py
index 89081e2..1ce60a1 100644
--- a/libmat2/exiftool.py
+++ b/libmat2/exiftool.py
@@ -20,13 +20,18 @@ class ExiftoolParser(abstract.AbstractParser):
     meta_allowlist = set()  # type: Set[str]
 
     def get_meta(self) -> Dict[str, Union[str, dict]]:
-        if self.sandbox:
-            out = bubblewrap.run([_get_exiftool_path(), '-json', self.filename],
-                                 input_filename=self.filename,
-                                 check=True, stdout=subprocess.PIPE).stdout
-        else:
-            out = subprocess.run([_get_exiftool_path(), '-json', self.filename],
-                                 check=True, stdout=subprocess.PIPE).stdout
+        try:
+            if self.sandbox:
+                out = bubblewrap.run([_get_exiftool_path(), '-json',
+                                      self.filename],
+                                     input_filename=self.filename,
+                                     check=True, stdout=subprocess.PIPE).stdout
+            else:
+                out = subprocess.run([_get_exiftool_path(), '-json',
+                                      self.filename],
+                                     check=True, stdout=subprocess.PIPE).stdout
+        except subprocess.CalledProcessError:  # pragma: no cover
+            raise ValueError
         meta = json.loads(out.decode('utf-8'))[0]
         for key in self.meta_allowlist:
             meta.pop(key, None)
-- 
GitLab