Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions haystack/components/converters/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def run(
logger.warning("Could not read {source}. Skipping it. Error: {error}", source=source, error=e)
continue

if not bytestream.data:
logger.warning("Skipping {source} because it is empty.", source=source)
continue

try:
text = extract(bytestream.data.decode("utf-8"), **merged_extraction_kwargs)
except Exception as conversion_e:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
``HTMLToDocument`` now skips ``ByteStream`` objects with empty content instead of
passing them to trafilatura. This prevents noisy lxml parse error logs (such as
"Document is empty") when a fetcher emits an empty stream.
17 changes: 17 additions & 0 deletions test/components/converters/test_html_to_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@ def test_run_error_handling(self, caplog):
assert "Could not read non_existing_file.html" in caplog.text
assert results["documents"] == []

def test_run_empty_bytestream(self, caplog):
"""
Test that an empty ByteStream is skipped without invoking extraction,
so no noisy lxml parse errors are emitted.
"""
empty_stream = ByteStream(data=b"")
empty_stream.mime_type = "text/html"
converter = HTMLToDocument()

with patch("haystack.components.converters.html.extract") as mock_extract:
with caplog.at_level(logging.WARNING):
results = converter.run(sources=[empty_stream])

assert results["documents"] == []
mock_extract.assert_not_called()
assert "because it is empty" in caplog.text

def test_mixed_sources_run(self, test_files_path):
"""
Test if the component runs correctly if the input is a mix of paths and ByteStreams.
Expand Down
Loading