FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update dump_devinfo to print original exception stack on errors. by sdb9696 · Pull Request #882 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
23 changes: 22 additions & 1 deletion devtools/dump_devinfo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.
Comment thread
rytilahti marked this conversation as resolved.

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

Back | FazBrowse Home | New Git URL