From 9fbb3801bb298419c5895883da99324748b0373e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 12 Apr 2017 11:01:39 +0200 Subject: [PATCH] Added a BlendFileError exception This avoid having to raise (and catch) an Exception instance. Catching such an exception is unnecessarily broad, as it'll also catch things like SyntaxError and AttributeError. --- bam/blend/blendfile.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bam/blend/blendfile.py b/bam/blend/blendfile.py index 69e8aea..e471bea 100644 --- a/bam/blend/blendfile.py +++ b/bam/blend/blendfile.py @@ -30,6 +30,10 @@ log = logging.getLogger("blendfile") FILE_BUFFER_SIZE = 1024 * 1024 +class BlendFileError(Exception): + """Raised when there was an error reading/parsing a blend file.""" + + # ----------------------------------------------------------------------------- # module global routines # @@ -73,9 +77,9 @@ def open_blend(filename, access="rb"): bfile.filepath_orig = filename return bfile else: - raise Exception("filetype inside gzip not a blend") + raise BlendFileError("filetype inside gzip not a blend") else: - raise Exception("filetype not a blend or a gzip blend") + raise BlendFileError("filetype not a blend or a gzip blend") def pad_up_4(offset): @@ -143,7 +147,7 @@ class BlendFile: self.blocks.append(block) if not self.structs: - raise Exception("No DNA1 block in file, this is not a valid .blend file!") + raise BlendFileError("No DNA1 block in file, this is not a valid .blend file!") # cache (could lazy init, incase we never use?) self.block_from_offset = {block.addr_old: block for block in self.blocks if block.code != b'ENDB'}