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), )