Commit eb6808111cd29294c8a7b8dc501e98f836015983

Authored by Christian Herdtweck
1 parent e97e15a6

create exception MsoExtractionError, raise from mso_file_extract

Showing 1 changed file with 10 additions and 2 deletions
oletools/olevba.py
@@ -304,6 +304,14 @@ class FileOpenError(Exception): @@ -304,6 +304,14 @@ class FileOpenError(Exception):
304 self.filename = filename 304 self.filename = filename
305 305
306 306
  307 +class MsoExtractionError(RuntimeError):
  308 + """ raised by mso_file_extract if parsing MSO/ActiveMIME data failed """
  309 +
  310 + def __init__(self, msg):
  311 + super(MsoExtractionError, self).__init__(msg)
  312 + self.msg = msg
  313 +
  314 +
307 #--- CONSTANTS ---------------------------------------------------------------- 315 #--- CONSTANTS ----------------------------------------------------------------
308 316
309 # URL and message to report issues: 317 # URL and message to report issues:
@@ -859,7 +867,7 @@ def mso_file_extract(data): @@ -859,7 +867,7 @@ def mso_file_extract(data):
859 :param data: bytes string, MSO/ActiveMime file content 867 :param data: bytes string, MSO/ActiveMime file content
860 :return: bytes string, extracted data (uncompressed) 868 :return: bytes string, extracted data (uncompressed)
861 869
862 - raise a RuntimeError if the data cannot be extracted 870 + raise a MsoExtractionError if the data cannot be extracted
863 """ 871 """
864 # check the magic: 872 # check the magic:
865 assert is_mso_file(data) 873 assert is_mso_file(data)
@@ -894,7 +902,7 @@ def mso_file_extract(data): @@ -894,7 +902,7 @@ def mso_file_extract(data):
894 return extracted_data 902 return extracted_data
895 except Exception: 903 except Exception:
896 log.exception('zlib decompression failed') 904 log.exception('zlib decompression failed')
897 - raise RuntimeError('Unable to decompress data from a MSO/ActiveMime file') 905 + raise MsoExtractionError('Unable to decompress data from a MSO/ActiveMime file')
898 906
899 907
900 #--- FUNCTIONS ---------------------------------------------------------------- 908 #--- FUNCTIONS ----------------------------------------------------------------