diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-12-20 06:58:53 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-12-20 07:01:05 +0300 |
commit | f0e3ea24be216bd98e8f2b75d722565a68461fb8 (patch) | |
tree | 800c3b313fb818b3b88bef26ee0e6aeab0529c2f /io_scene_fbx | |
parent | dba7a10556f31bed867b463f0448d7b378dcef8b (diff) |
Fix T72413: FBX import error on missing files
While it's an error case, the ascii detection caused
the missing file case to raise a full exception before running
code which handles this case more gracefully.
Diffstat (limited to 'io_scene_fbx')
-rw-r--r-- | io_scene_fbx/import_fbx.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py index 751a2b17..32b887c1 100644 --- a/io_scene_fbx/import_fbx.py +++ b/io_scene_fbx/import_fbx.py @@ -2307,17 +2307,6 @@ class FbxImportHelperNode: return None -def is_ascii(filepath, size): - with open(filepath, 'r', encoding="utf-8") as f: - try: - f.read(size) - return True - except UnicodeDecodeError: - pass - - return False - - def load(operator, context, filepath="", use_manual_orientation=False, axis_forward='-Z', @@ -2358,10 +2347,24 @@ def load(operator, context, filepath="", perfmon.step("FBX Import: start importing %s" % filepath) perfmon.level_up() - # detect ascii files - if is_ascii(filepath, 24): + # Detect ASCII files. + + # Typically it's bad practice to fail silently on any error, + # however the file may fail to read for many reasons, + # and this situation is handled later in the code, + # right now we only want to know if the file successfully reads as ascii. + try: + with open(filepath, 'r', encoding="utf-8") as fh: + fh.read(24) + is_ascii = True + except Exception: + is_ascii = False + + if is_ascii: operator.report({'ERROR'}, "ASCII FBX files are not supported %r" % filepath) return {'CANCELLED'} + del is_ascii + # End ascii detection. try: elem_root, version = parse_fbx.parse(filepath) |