Fix error handling in DirectoryReader class

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-04-03 16:47:31 -03:00
commit 2f0ce80d19

View file

@ -3,9 +3,11 @@ import os
import zlib
from pathlib import Path
from langflow.interface.custom.custom_component import CustomComponent
from loguru import logger
from langflow.interface.custom.custom_component import CustomComponent
from langflow.interface.custom.custom_component import CustomComponent
class CustomComponentPathValueError(ValueError):
pass
@ -198,7 +200,12 @@ class DirectoryReader:
Process a file by validating its content and
returning the result and content/error message.
"""
file_content = self.read_file_content(file_path)
try:
file_content = self.read_file_content(file_path)
except Exception as exc:
logger.exception(exc)
logger.error(f"Error while reading file {file_path}: {str(exc)}")
return False, f"Could not read {file_path}"
if file_content is None:
return False, f"Could not read {file_path}"