Skip to content

Conversation

kdmukai
Copy link
Contributor

@kdmukai kdmukai commented Apr 29, 2025

The problem

When the camera cable is not properly / fully connected, any attempt to access the camera (live preview video, I/O test still image capture) results in this misleading error:


This PR

  • Explicitly handles the PiCameraError and shows a more useful error message via a new custom error handler CameraConnectionErrorView:

CameraConnectionErrorView

  • Adds a flow test to verify the exception routing to the above error view.

Implementation note

The test suite and screenshot generator now extend the module mock:

# before
sys.modules['seedsigner.hardware.camera'] = MagicMock()

# after
sys.modules['seedsigner.hardware.camera.Camera'] = MagicMock()

This is because the UnhandledExceptionView now tests for CameraConnectionError.__name__ which will be unavailable if the original module mock as unchanged (the seedsigner.hardware.camera.CameraConnectionError class would be mocked out of existence and that View would throw an error when trying to access the now nonexistent error class's __name__).


How to test

Boot a SeedSigner with its camera disconnected. Access any View that relies on camera data (e.g. "Scan" from Home, Load Seed via SeedQR, New Seed via image entropy, I/O test still image, etc).


Misc:

Minor button label changes on error screens from "Done" or "I understand" to "Back to Main Menu":

OptionDisabledView OptionDisabledView

ScanInvalidQRTypeView ScanInvalidQRTypeView

UnhandledExceptionView UnhandledExceptionView


This pull request is categorized as a:

  • Code refactor

Checklist

  • I’ve run pytest and made sure all unit tests pass before sumbitting the PR

If you modified or added functionality/workflow, did you add new unit tests?

  • N/A; test suite cannot run hardware-level code

I have tested this PR on the following platforms/os:

self._video_stream.start()
except PiCameraError:
# This error most often occurs because the camera connection is loose
from seedsigner.hardware.camera import CameraConnectionError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CameraConnectionError is being imported here even though it's defined in the same file — is there a specific reason for that? Just checking in case I'm missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, nice catch!

I had originally put this try/except in PiVideoStream but when I moved it here the now-unnecessary import came along with it.

@kdmukai kdmukai force-pushed the camera_connection_error branch from 616faa2 to a7a4f8c Compare May 1, 2025 14:22
@bitcoinprecept
Copy link
Contributor

CACK

@newtonick newtonick added the enhancement New feature or request label May 25, 2025
@newtonick newtonick added this to the 0.8.6 milestone May 25, 2025
@newtonick newtonick modified the milestones: 0.8.6, 0.9.0 Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 9.0 Needs Code Review
Development

Successfully merging this pull request may close these issues.

4 participants