From 87a30a0dbbc2bf926f8eee9a60ea9830741f8dcf Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Fri, 5 Nov 2021 08:21:06 +0200 Subject: [PATCH] Add error handling --- image_classifier/image_classifier.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/image_classifier/image_classifier.py b/image_classifier/image_classifier.py index 0c84908..6be4bb9 100755 --- a/image_classifier/image_classifier.py +++ b/image_classifier/image_classifier.py @@ -85,8 +85,11 @@ class image_classifier: self._log.debug(f"People (before): {self.metadata['Xmp.iptcExt.PersonInImage'].raw_value} (type: {type(self.metadata['Xmp.iptcExt.PersonInImage'].raw_value)})") self.append_people(people) self._log.debug(f"People (after): {self.metadata['Xmp.iptcExt.PersonInImage'].raw_value} (type: {type(self.metadata['Xmp.iptcExt.PersonInImage'].raw_value)})") - self.metadata.write() - self._log.debug(f"Updated file '{file}'.") + try: + self.metadata.write() + self._log.debug(f"Updated file '{file}'.") + except OSError as error: + self._log.error(f"Error writing metadata to picture file. {error}") if 'Exif.Photo.DateTimeOriginal' in self.metadata.exif_keys: original_date = self.metadata['Exif.Photo.DateTimeOriginal'].value self._log.debug(f"File creation time: {original_date} (type: {type(original_date)})")