From: Michael Tremer Date: Mon, 16 Feb 2026 17:03:49 +0000 (+0000) Subject: sources: Gracefully skip if a source has given us an empty file X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a900bcedbfacccd62f91b284bd0eb1a6689d3fee;p=dbl.git sources: Gracefully skip if a source has given us an empty file Signed-off-by: Michael Tremer --- diff --git a/src/dbl/sources.py b/src/dbl/sources.py index bd4ae37..f2c9870 100644 --- a/src/dbl/sources.py +++ b/src/dbl/sources.py @@ -220,8 +220,13 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True): # Consume, transparently decompress and decode the payload f = self._consume_payload(response) + # Count parsed lines + lineno = 0 + # Add all domains for line in f: + lineno += 1 + # Strip any comments line, hashtag, comment = line.partition("#") @@ -302,11 +307,20 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True): # Add the domain domains.add(domain) + # If we downloaded no data, we skip any further processing + if lineno == 0: + log.warning("Downloaded an empty file from %s (%s). Skipping..." \ + % (self, self.url)) + + return False + # Log an error if we could not detect the format if format is None: log.error("Format of '%s' (%s) seems to be unkown. No data could be parsed" \ % (self, self.url)) + return False + # Add all domains to the database self.add_domains(domains)