Skip to content

fix(#93): raise DevicePassCmdError instead of DeviceDecryptionError when DevicePassCmd fails#108

Draft
Copilot wants to merge 1 commit intomainfrom
copilot/copilotupdate-open-functionality-fix-device-decryp
Draft

fix(#93): raise DevicePassCmdError instead of DeviceDecryptionError when DevicePassCmd fails#108
Copilot wants to merge 1 commit intomainfrom
copilot/copilotupdate-open-functionality-fix-device-decryp

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 26, 2026

Fixes #93.

Problem

When DevicePassCmd fails to execute (e.g. because the password reference is incorrect), the error was wrapped in sdm.DeviceDecryptionError. This is misleading because no decryption was ever attempted — the password command itself failed before cryptsetup was even invoked.

Solution

Added a new DevicePassCmdError exception and two wrapper functions in device_managers.py that separate the execution of the password command from the actual cryptsetup decryption:

  • open_encrypted_device: runs the pass_cmd first in isolation. If it fails, raises DevicePassCmdError. If it succeeds, pipes the password to cryptsetup; if that fails, raises sdm.DeviceDecryptionError.
  • decrypted_device: context manager using the above function.

cli.py is updated to use these wrappers instead of calling the storage_device_managers functions directly.

Changes

  • src/butter_backup/device_managers.py: add DevicePassCmdError, open_encrypted_device, and decrypted_device
  • src/butter_backup/cli.py: use the new wrappers from device_managers
  • tests/test_device_managers.py: new test file verifying that:
    • a failing DevicePassCmd raises DevicePassCmdError (not DeviceDecryptionError)
    • a wrong password (pass_cmd succeeds, cryptsetup fails) still raises DeviceDecryptionError

…hen DevicePassCmd fails

When DevicePassCmd fails (e.g. incorrect password reference), the previous code
wrapped the error in sdm.DeviceDecryptionError, which was misleading because no
decryption was ever attempted.

- Add DevicePassCmdError exception to device_managers.py
- Add open_encrypted_device wrapper that separates pass_cmd execution from
  cryptsetup, raising DevicePassCmdError on pass_cmd failure
- Add decrypted_device context manager wrapper using the new function
- Update cli.py to use the new wrappers instead of sdm.open_encrypted_device
  and sdm.decrypted_device
- Add tests verifying the correct exception type is raised in each case

Agent-Logs-Url: https://github.com/MaxG87/ButterBackup/sessions/c09c185a-8901-460d-acbc-8519ba60daa0

Co-authored-by: MaxG87 <5477952+MaxG87@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fehler in DevicePassCmd wird als DeviceDecryptionError gemeldet

2 participants