Skip to content

Exception handling in _copy_data is too broad #255

Closed
@johnnicely-cl

Description

@johnnicely-cl

Describe the bug
We inadvertently passed the wrong data type into the encrypt_file method. While the error was logged, it does not result in an exception that we can catch, which caused the task encrypting data to be marked as successful even though it had failed. The error message was:

[2025-05-21T18:59:50.163+0000] {gnupg.py:167} ERROR - Error sending data
Traceback (most recent call last):
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/gnupg.py", line 161, in _copy_data
    outstream.write(data)
TypeError: a bytes-like object is required, not 'str'

This exception is not passed up the stack because it is swallowed at line 167.

To Reproduce
Steps to reproduce the behavior:

  1. Call encrypt_file with a string instead of a bytes-like object.

Expected behavior
The TypeError should be thrown up the stack.

Screenshots
N/A

Environment

  • OS: Linux
  • Version of this library: 0.5.4
  • Version of GnuPG: 2.3.7

Additional information
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions