Skip to content

Commit

Permalink
Add logging in case of invalid CSS.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Feb 8, 2024
1 parent 88bce6f commit db8c7ac
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/warc2zim/content_rewriting/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)
from tinycss2.serializer import serialize_url

from warc2zim.constants import logger
from warc2zim.content_rewriting import UrlRewriterProto
from warc2zim.content_rewriting.rx_replacer import RxRewriter

Expand Down Expand Up @@ -51,6 +52,13 @@ def rewrite(self, content: str | bytes) -> str:
# If tinycss fail to parse css, it will generate a "Error" token.
# Exception is raised at serialization time.
# We try/catch the whole process to be sure anyway.
logger.warning(
(
"Css transformation fails. Fallback to regex rewriter.\n"
"Article path is %s"
),
self.url_rewriter.article_url,
)
return self.fallback_rewriter.rewrite_content(content, {})
return output

Expand All @@ -64,6 +72,13 @@ def rewrite_inline(self, content: str) -> str:
# If tinycss fail to parse css, it will generate a "Error" token.
# Exception is raised at serialization time.
# We try/catch the whole process to be sure anyway.
logger.warning(
(
"Css transformation fails. Fallback to regex rewriter.\n"
"Content is `%s`"
),
content,
)
return self.fallback_rewriter.rewrite_content(content, {})

def process_list(self, components: Iterable[ast.Node]):
Expand Down

0 comments on commit db8c7ac

Please sign in to comment.