What changed, and why it matters
This commit fixes a Python indentation bug in the COLDCARD firmware's export function. The exception handlers for missing microSD card and write failures were placed outside the code block that actually tries to write, meaning they would never catch those errors. The fix simply indents them so they sit inside the try block. Without the fix, if a write fails, the user may see an unhandled error instead of a friendly message, and the normal cleanup/return path after a write may not run as intended.
Apply the indentation fix and add regression tests covering the CardMissingError and generic write-failure paths in export_contents() to ensure exceptions are caught and the user receives the intended on-screen message.
Security signals we found
Exception handler placed outside the protected try block, causing unhandled runtime errors
Missing error handling for SD card write failures in export workflow
Potential UI/UX failure path that could leave export state inconsistent
Evidence from the diff
In shared/export.py, the export_contents() function had a try block containing the write attempt, but the except CardMissingError and except Exception clauses were dedented to the same level as the try, making them syntactically attached to an outer scope and therefore unreachable for the write exceptions. The patch indents both except clauses so they are now part of the try block. This restores intended error handling and ensures the subsequent cleanup/return logic executes correctly after either success or a handled exception.
Changed components
shared/export.pyexport_contents() functionmicroSD card export error handlingInspect captured patch +4 / −4
diff --git a/shared/export.py b/shared/export.py
index 90c5a4c..b30bb3d 100644
--- a/shared/export.py
+++ b/shared/export.py
@@ -92,10 +92,10 @@ async def export_contents(title, contents, fname_pattern, derive=None, addr_fmt=
await ux_show_story(msg)
- except CardMissingError:
- await needs_microsd()
- except Exception as e:
- await ux_show_story('Failed to write!\n\n' + str(e))
+ except CardMissingError:
+ await needs_microsd()
+ except Exception as e:
+ await ux_show_story('Failed to write!\n\n' + str(e))
# both exceptions & success gets here
if no_qr and (NFC is None) and (VD is None) and not force_prompt:
Why this scored 23/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.