Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Add stack decoding information to logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mawildoer committed Sep 13, 2024
1 parent e485417 commit 00c5183
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/faebryk/libs/sexp/dataclass_sexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ class DecodeError(Exception):
"""Error during decoding"""


def _prettify_stack(stack: list[tuple[str, type]] | None) -> str:
if stack is None:
return "<top-level>"
return ".".join(s[0] for s in stack)


def _convert(
val,
t,
Expand Down Expand Up @@ -117,8 +123,9 @@ def _convert(
except DecodeError:
raise
except Exception as e:
pretty_stack = ".".join(s[0] for s in substack)
raise DecodeError(f"Failed to decode {pretty_stack} ({t}) with {val} ") from e
raise DecodeError(
f"Failed to decode {_prettify_stack(substack)} ({t}) with {val} "
) from e


netlist_obj = str | Symbol | int | float | bool | list
Expand Down Expand Up @@ -178,6 +185,7 @@ def _decode[T](
unprocessed_indices = unprocessed_indices - set(pos_values.keys())

if logger.isEnabledFor(logging.DEBUG):
logger.debug(f"processing: {_prettify_stack(stack)}")
logger.debug(f"key_fields: {list(key_fields.keys())}")
logger.debug(
f"positional_fields: {list(f.name for f in positional_fields.values())}"
Expand All @@ -189,7 +197,7 @@ def _decode[T](
unprocessed_values = [sexp[i] for i in unprocessed_indices]
# This is separate from the above loop to make it easier to debug during dev
if logger.isEnabledFor(logging.DEBUG):
logger.debug(f"Unprocessed values: {unprocessed_values}")
logger.debug(f"unprocessed values: {unprocessed_values}")

# Parse --------------------------------------------------------------

Expand Down

0 comments on commit 00c5183

Please sign in to comment.