fix: set valid=false for invalid backends (#171)

* fix: set valid=false for invalid backends

Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>

* Add test case for InputDocument

Signed-off-by: Christoph Auer <cau@zurich.ibm.com>

---------

Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
Co-authored-by: Christoph Auer <cau@zurich.ibm.com>
This commit is contained in:
Michele Dolfi
2024-10-23 15:52:30 +02:00
committed by GitHub
parent b8d2286dd1
commit 3496b4838f
2 changed files with 62 additions and 0 deletions

View File

@@ -143,11 +143,13 @@ class InputDocument(BaseModel):
self.valid = False
except (FileNotFoundError, OSError) as e:
self.valid = False
_log.exception(
f"File {self.file.name} not found or cannot be opened.", exc_info=e
)
# raise
except RuntimeError as e:
self.valid = False
_log.exception(
f"An unexpected error occurred while opening the document {self.file.name}",
exc_info=e,
@@ -166,6 +168,8 @@ class InputDocument(BaseModel):
)
self._backend = backend(self, path_or_stream=path_or_stream)
if not self._backend.is_valid():
self.valid = False
class DocumentFormat(str, Enum):