Skip to content

Commit 7c704bb

Browse files
committed
Make the text parser log warnings instead of raising exceptions
1 parent 2f07e7a commit 7c704bb

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

pyrogram/client/parser/html.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import html
20+
import logging
2021
import re
2122
from collections import OrderedDict
2223
from html.parser import HTMLParser
@@ -27,6 +28,8 @@
2728
from pyrogram.errors import PeerIdInvalid
2829
from . import utils
2930

31+
log = logging.getLogger(__name__)
32+
3033

3134
class Parser(HTMLParser):
3235
MENTION_RE = re.compile(r"tg://user\?id=(\d+)")
@@ -94,7 +97,7 @@ def handle_endtag(self, tag):
9497
line, offset = self.getpos()
9598
offset += 1
9699

97-
raise ValueError("Unmatched closing tag </{}> at line {}:{}".format(tag, line, offset))
100+
log.warning("Unmatched closing tag </{}> at line {}:{}".format(tag, line, offset))
98101
else:
99102
if not self.tag_entities[tag]:
100103
self.tag_entities.pop(tag)
@@ -120,7 +123,7 @@ def parse(self, text: str):
120123
for tag, entities in parser.tag_entities.items():
121124
unclosed_tags.append("<{}> (x{})".format(tag, len(entities)))
122125

123-
raise ValueError("Unclosed tags: {}".format(", ".join(unclosed_tags)))
126+
log.warning("Unclosed tags: {}".format(", ".join(unclosed_tags)))
124127

125128
entities = []
126129

0 commit comments

Comments
 (0)