Skip to content

gh-122909: Pass ftp error strings to URLError constructor #122913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 20, 2024

Conversation

jeremyhylton
Copy link
Contributor

@jeremyhylton jeremyhylton commented Aug 11, 2024

ftplib exceptions are very simple. They inherit from Exception and define no additional behavior. The modules raises exceptions that just take a single string argument.

The URLError exception constructor takes a string that description the error.

Fix the handler for ftp errors to pass the original error string to URLError() instead of the ftplib.Error() instance.

@jeremyhylton
Copy link
Contributor Author

The change here is debatable. The docs says that URLError() can be passed a string or an object, and the implementation actually allows two arguments (where the second is stored as filename). According to those docs, the original code is correct and we should actually change test/support/sockethelper to check the type of the URLError reason.

However, the urllib code for ftp support mostly passes strings to URLError instead of ftplib.Error instances. This change would make the code more consistent, at the risk of breaking some client code that depended on exactly the implementation of error handling for ftp.

@gpshead
Copy link
Member

gpshead commented Aug 13, 2024

The consistency is good, but we should mention this minor behavior in a NEWS entry.

@freakboy3742
Copy link
Contributor

FWIW - I agree that this change makes sense. However long the current behavior has existed, it strikes me as incorrect.

@ghost
Copy link

ghost commented Aug 19, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@jeremyhylton jeremyhylton enabled auto-merge (squash) August 20, 2024 00:25
@jeremyhylton jeremyhylton merged commit 77133f5 into python:main Aug 20, 2024
34 checks passed
blhsing pushed a commit to blhsing/cpython that referenced this pull request Aug 22, 2024
…on#122913)

* pass the original string error message from the ftplib error to URLError()

* Update request.py

Change error string for ftp error to be consistent with other errors reported for ftp

* Add NEWS entry for change to urllib.request for ftp errors.

* Track the change in the ftp error message in the test.
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.

4 participants