Skip to content

Commit

Permalink
Better exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
erikogabrielsson committed Jul 1, 2024
1 parent d96c045 commit 9615186
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion opentile/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pathlib import Path
from typing import Any, BinaryIO, Dict, Optional, Union

from tifffile import TiffPageSeries, TiffPages, TiffFile
from tifffile import TiffFileError, TiffPageSeries, TiffPages, TiffFile
from upath import UPath
from fsspec.core import open

Expand Down Expand Up @@ -45,6 +45,9 @@ def __init__(
opened_file: BinaryIO = open(str(file), **options or {}) # type: ignore
try:
self._tiff_file = TiffFile(opened_file)
except (FileNotFoundError, TiffFileError):
opened_file.close()
raise
except Exception as exception:
opened_file.close()
raise Exception(f"Failed to open file {file}") from exception
Expand Down

0 comments on commit 9615186

Please sign in to comment.