Repository: phidatahq/phidata
File: libs/agno/agno/knowledge/reader/text_reader.py (Python)

Code before:
        except Exception as e:
            log_error(f"Error reading: {file}: {e}")
            return []

    async def async_read(self, file: Union[Path, IO[Any]], name: Optional[str] = None) -> List[Document]:
        try:
            if isinstance(file, Path):
                if not file.exists():
                    raise FileNotFoundError(f"Could not find file: {file}")

                log_debug(f"Reading asynchronously: {file}")
                file_name = name or file.stem

                try:
                    import aiofiles

                    async with aiofiles.open(file, "r", encoding=self.encoding or "utf-8") as f:
                        file_contents = await f.read()
                except ImportError:
                    log_warning("aiofiles not installed, using synchronous file I/O")
                    file_contents = file.read_text(self.encoding or "utf-8")
            else:
                # Handle BytesIO and other file-like objects that may not have a name attribute
                if name:
                    file_name = name
                elif hasattr(file, "name") and file.name:
                    file_name = file.name.split(".")[0]
                else:
                    file_name = "text_file"
                log_debug(f"Reading uploaded file asynchronously: {file_name}")
                file.seek(0)
                file_contents = file.read().decode(self.encoding or "utf-8")

            document = Document(
                name=file_name,
                id=str(uuid.uuid4()),
                content=file_contents,
            )

            if self.chunk:
                return await self._async_chunk_document(document)
            return [document]
        except Exception as e:
            log_error(f"Error reading asynchronously: {file}: {e}")
            return []

    async def _async_chunk_document(self, document: Document) -> List[Document]:
        if not self.chunk or not document:
            return [document]

        async def process_chunk(chunk_doc: Document) -> Document:

Review comment (suggestion):
```suggestion
                elif hasattr(file, "name") and file.name is not None:
```

Code after:
        except Exception as e:
            log_error(f"Error reading: {file}: {e}")
            return []

    async def async_read(self, file: Union[Path, IO[Any]], name: Optional[str] = None) -> List[Document]:
        try:
            if isinstance(file, Path):
                if not file.exists():
                    raise FileNotFoundError(f"Could not find file: {file}")

                log_debug(f"Reading asynchronously: {file}")
                file_name = name or file.stem

                try:
                    import aiofiles

                    async with aiofiles.open(file, "r", encoding=self.encoding or "utf-8") as f:
                        file_contents = await f.read()
                except ImportError:
                    log_warning("aiofiles not installed, using synchronous file I/O")
                    file_contents = file.read_text(self.encoding or "utf-8")
            else:
                # Handle BytesIO and other file-like objects that may not have a name attribute
                if name:
                    file_name = name
                elif hasattr(file, "name") and file.name is not None:
                    file_name = file.name.split(".")[0]
                else:
                    file_name = "text_file"
                log_debug(f"Reading uploaded file asynchronously: {file_name}")
                file.seek(0)
                file_contents = file.read().decode(self.encoding or "utf-8")

            document = Document(
                name=file_name,
                id=str(uuid.uuid4()),
                content=file_contents,
            )

            if self.chunk:
                return await self._async_chunk_document(document)
            return [document]
        except Exception as e:
            log_error(f"Error reading asynchronously: {file}: {e}")
            return []

    async def _async_chunk_document(self, document: Document) -> List[Document]:
        if not self.chunk or not document:
            return [document]

        async def process_chunk(chunk_doc: Document) -> Document: