refactor(core): remove unneeded try-except block
What changed, and why it matters
This commit removes a try-except block that simply caught all exceptions and immediately re-raised them. It is a code cleanup with no functional change to how errors are handled.
No security action required. Treat as a normal refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff removes a try:/except Exception: raise wrapper around the main body of a while True loop in core/src/trezor/ui/__init__.py. Because the except clause only re-raises the same exception without filtering, logging, or modifying behavior, the try-except was behaviorally a no-op. The indentation of the wrapped code is reduced accordingly. No exception handling logic, message parsing, state transitions, or control flow semantics are altered.
Changed components
core/src/trezor/ui/__init__.pyInspect captured patch +25 / −28
diff --git a/core/src/trezor/ui/__init__.py b/core/src/trezor/ui/__init__.py
index 4eca89551..d4f9986f8 100644
--- a/core/src/trezor/ui/__init__.py
+++ b/core/src/trezor/ui/__init__.py
@@ -460,36 +460,33 @@ class Layout(Generic[T]):
if self.context is None:
return
while True:
- try:
- # The following task will raise `UnexpectedMessageException` on any message.
- unexpected_read = self.context.read(())
- result = await loop.race(unexpected_read, self.button_request_box)
- if result is None:
- return # exit the loop when the layout is done.
- assert isinstance(result, tuple)
- br_code, br_name = result
+ # The following task will raise `UnexpectedMessageException` on any message.
+ unexpected_read = self.context.read(())
+ result = await loop.race(unexpected_read, self.button_request_box)
+ if result is None:
+ return # exit the loop when the layout is done.
+ assert isinstance(result, tuple)
+ br_code, br_name = result
+ if __debug__:
+ log.info(__name__, "ButtonRequest sent: %s", br_name)
+ await self.context.call(
+ ButtonRequest(
+ code=br_code, pages=self.layout.page_count(), name=br_name
+ ),
+ ButtonAck,
+ )
+ if __debug__:
+ log.info(__name__, "ButtonRequest acked: %s", br_name)
+
+ if (
+ self.button_request_ack_pending
+ and self.state is LayoutState.TRANSITIONING
+ ):
+ self.button_request_ack_pending = False
+ self.state = LayoutState.ATTACHED
if __debug__:
- log.info(__name__, "ButtonRequest sent: %s", br_name)
- await self.context.call(
- ButtonRequest(
- code=br_code, pages=self.layout.page_count(), name=br_name
- ),
- ButtonAck,
- )
- if __debug__:
- log.info(__name__, "ButtonRequest acked: %s", br_name)
-
- if (
- self.button_request_ack_pending
- and self.state is LayoutState.TRANSITIONING
- ):
- self.button_request_ack_pending = False
- self.state = LayoutState.ATTACHED
- if __debug__:
- self.notify_debuglink(self)
- except Exception:
- raise
+ self.notify_debuglink(self)
finally:
if is_done is not None:
is_done.put(None)
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.