anibali / pyisyntax

A Python library for working with iSyntax file format images
MIT License
2 stars 2 forks source link

Attribute error when closing of unsupported file #8

Closed erikogabrielsson closed 5 months ago

erikogabrielsson commented 5 months ago

Hi,

When using ISyntax as a contextmanager and trying to open an unsupported file, libisyntax.open_from_registered_handle() will throw LibISyntaxFatalError, and when __exit__() calls close() there will be an AttributeError as closed has not yet been set. The same thing can likely happen if register_io() throws.

from isyntax import ISyntax
from isyntax.lowlevel.libisyntax import LibISyntaxFatalError
try:
    with ISyntax.open("some non-isyntax file") as wsi:
        pass
except LibISyntaxFatalError:
    pass
Exception ignored in: <function ISyntax.__del__ at 0x00000156C209F4C0>
Traceback (most recent call last):
  File "c:\work\notebooks\.venv311\Lib\site-packages\isyntax\wrapper.py", line 231, in __del__
    self.close()
  File "c:\work\notebooks\.venv311\Lib\site-packages\isyntax\wrapper.py", line 96, in close
    if self.closed:
       ^^^^^^^^^^^
AttributeError: 'ISyntax' object has no attribute 'closed'
anibali commented 5 months ago

Fixed in https://github.com/anibali/pyisyntax/commit/02f00ba015e6de6988c7a55a2493e3a60796b8ea

Thanks for the detailed information!