refactor(core): use `NoWireContext` in `_get_cache_for_key()`
What changed, and why it matters
This is a tiny internal code cleanup in Trezor firmware. It changes the way the code reports an error when there is no active communication context, switching from a generic 'Exception' to a more specific 'NoWireContext' error type. The behavior is essentially the same; it just uses a clearer internal error label. There is no indication this fixes or introduces a security problem.
No security action needed. Treat as normal code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors _get_cache_for_key() in core/src/trezor/wire/context.py. Previously, when CURRENT_CONTEXT was falsy (None or empty), it raised a generic Exception(‘No wire context’). Now it explicitly checks ‘if CURRENT_CONTEXT is None’ and raises the existing NoWireContext exception, then returns CURRENT_CONTEXT.cache. This is a behavior-preserving refactor with no functional security change visible in the diff.
Changed components
core/src/trezor/wire/context.pyInspect captured patch +3 / −3
diff --git a/core/src/trezor/wire/context.py b/core/src/trezor/wire/context.py
index 8fc01e14f..3560b17e7 100644
--- a/core/src/trezor/wire/context.py
+++ b/core/src/trezor/wire/context.py
@@ -218,6 +218,6 @@ def cache_delete(key: int) -> None:
def _get_cache_for_key(key: int) -> DataCache:
if key & SESSIONLESS_FLAG:
return cache.get_sessionless_cache()
- if CURRENT_CONTEXT:
- return CURRENT_CONTEXT.cache
- raise Exception("No wire context")
+ if CURRENT_CONTEXT is None:
+ raise NoWireContext
+ return CURRENT_CONTEXT.cache
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.