You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using defused xml with rich traceback formatter the library always throws a weird error complaining about the type of exception. Everything is ok when using import xml.etree.cElementTree as xmlctree.
importioimportdefusedxml.ElementTreeasxmlctreeimportstructlogrich_tracebacks_fmt=structlog.dev.RichTracebackFormatter()
structlog.configure(
cache_logger_on_first_use=True,
processors=[
# show log levelstructlog.stdlib.add_log_level,
# add time to every log entrystructlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M.%S"),
# render logs in pretty format (unstructured) + beautiful tracebacksstructlog.dev.ConsoleRenderer(exception_formatter=rich_tracebacks_fmt),
],
)
logger=structlog.get_logger()
try:
for_, eleminxmlctree.iterparse(io.BytesIO(b"sdsds")):
print(elem)
exceptExceptionase:
logger.exception(str(e))
traceback
> python feed_loader/test.py
Traceback (most recent call last):
File "project/.venv/lib/python3.11/xml/etree/ElementTree.py", line 1716, in close
self.parser.Parse(b"", True) # end of data
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
xml.parsers.expat.ExpatError: syntax error: line 1, column 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "project/feed_loader/test.py", line 24, in <module>
for _, elem in xmlctree.iterparse(io.BytesIO(b"sdsds")):
File "project/.venv/lib/python3.11/xml/etree/ElementTree.py", line 1255, in iterator
root = pullparser._close_and_return_root()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "project/.venv/lib/python3.11/xml/etree/ElementTree.py", line 1298, in _close_and_return_root
root = self._parser.close()
^^^^^^^^^^^^^^^^^^^^
File "project/.venv/lib/python3.11/xml/etree/ElementTree.py", line 1718, in close
self._raiseerror(v)
File "project/.venv/lib/python3.11/xml/etree/ElementTree.py", line 1618, in _raiseerror
raise err
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "project/feed_loader/test.py", line 27, in <module>
logger.exception(str(e))
File "project/.venv/lib/python3.11/site-packages/structlog/_log_levels.py", line 88, in exception
return self.error(event, *args, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "project/.venv/lib/python3.11/site-packages/structlog/_log_levels.py", line 168, in meth
return self._proxy_to_logger(name, event, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "project/.venv/lib/python3.11/site-packages/structlog/_base.py", line 222, in _proxy_to_logger
args, kw = self._process_event(method_name, event, event_kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "project/.venv/lib/python3.11/site-packages/structlog/_base.py", line 171, in _process_event
event_dict = proc(self._logger, method_name, event_dict)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "project/.venv/lib/python3.11/site-packages/structlog/dev.py", line 505, in __call__
self._exception_formatter(sio, exc_info)
File "project/.venv/lib/python3.11/site-packages/structlog/dev.py", line 217, in __call__
Console(file=sio, color_system=self.color_system).print(
File "project/.venv/lib/python3.11/site-packages/rich/console.py", line 1700, in print
extend(render(renderable, render_options))
File "project/.venv/lib/python3.11/site-packages/rich/console.py", line 1332, in render
for render_output in iter_render:
File "project/.venv/lib/python3.11/site-packages/rich/traceback.py", line 545, in __rich_console__
highlighter(stack.syntax_error.msg),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "project/.venv/lib/python3.11/site-packages/rich/highlighter.py", line 37, in __call__
raise TypeError(f"str or Text instance required, not {text!r}")
The text was updated successfully, but these errors were encountered:
Hello!
When using defused xml with
rich
traceback formatter the library always throws a weird error complaining about the type of exception. Everything is ok when usingimport xml.etree.cElementTree as xmlctree
.traceback
The text was updated successfully, but these errors were encountered: