From e0754d16090f4c59f49500e430fed54da3631d14 Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 18 Feb 2022 15:44:18 +0100 Subject: [PATCH] fix(python/protobuf): correctly dump messages with missing required fields --- python/.changelog.d/2135.fixed | 1 + python/src/trezorlib/protobuf.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 python/.changelog.d/2135.fixed diff --git a/python/.changelog.d/2135.fixed b/python/.changelog.d/2135.fixed new file mode 100644 index 000000000..8c6563f4f --- /dev/null +++ b/python/.changelog.d/2135.fixed @@ -0,0 +1 @@ +Fixed error when printing protobuf message with a missing required field. diff --git a/python/src/trezorlib/protobuf.py b/python/src/trezorlib/protobuf.py index 1f8e365b2..2ef2ee5e3 100644 --- a/python/src/trezorlib/protobuf.py +++ b/python/src/trezorlib/protobuf.py @@ -550,9 +550,13 @@ def format_message( return repr(value) - return "{name} ({size} bytes) {content}".format( + try: + byte_size = str(pb.ByteSize()) + " bytes" + except Exception: + byte_size = "encoding failed" + return "{name} ({size}) {content}".format( name=pb.__class__.__name__, - size=pb.ByteSize(), + size=byte_size, content=pformat("", pb.__dict__, indent), )