Skip to content
Merged
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
23 changes: 22 additions & 1 deletion devtools/dump_devinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import json
import logging
import re
import sys
import traceback
from collections import defaultdict, namedtuple
from pathlib import Path
Expand Down Expand Up @@ -343,6 +344,26 @@ def _echo_error(msg: str):
)


def format_exception(e):
"""Print full exception stack as if it hadn't been caught.

https://stackoverflow.com/a/12539332
"""
exception_list = traceback.format_stack()
exception_list = exception_list[:-2]
exception_list.extend(traceback.format_tb(sys.exc_info()[2]))
exception_list.extend(
traceback.format_exception_only(sys.exc_info()[0], sys.exc_info()[1])
)

exception_str = "Traceback (most recent call last):\n"
exception_str += "".join(exception_list)
# Removing the last \n
exception_str = exception_str[:-1]

return exception_str


async def _make_requests_or_exit(
device: SmartDevice,
requests: list[SmartRequest],
Expand Down Expand Up @@ -389,7 +410,7 @@ async def _make_requests_or_exit(
f"Unexpected exception querying {name} at once: {ex}",
)
if _LOGGER.isEnabledFor(logging.DEBUG):
traceback.print_stack()
_echo_error(format_exception(ex))
exit(1)
finally:
await device.protocol.close()
Expand Down