Skip to content
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

Refactor proxy settings and add error handling #8033

Merged
merged 1 commit into from
May 24, 2024
Merged

Conversation

drew2a
Copy link
Contributor

@drew2a drew2a commented May 22, 2024

Reworked the 'set_proxy_settings' function in the download manager to handle invalid port values more gracefully. The function now attempts to convert the port value to an integer and logs any ValueError exceptions that occur during this process. This prevents crashes when non-integer values are provided for the port. Also, reorganized import statements according to PEP8 guidelines.

Additionally, a new test case 'test_set_proxy_settings_invalid_port' has been added to verify this behavior. It checks if proxy settings are not set when an invalid port number is provided.

Fixes #8014

@drew2a drew2a marked this pull request as ready for review May 22, 2024 11:30
@drew2a drew2a requested review from a team and xoriole and removed request for a team May 22, 2024 11:30
@drew2a drew2a requested a review from xoriole May 23, 2024 09:11
proxy_port = None

try:
proxy_port = int(server[1])
Copy link
Contributor

Choose a reason for hiding this comment

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

Under the possibility of server[1] being None which causes int(server[1]) to raise TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType', I would suggest to keep the initial if statement:

if server and server[0] and server[1]:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right about the technical possibility of server[1] being None. This could be due to wrongly formatted settings. If we start considering these corner cases, then we should also check that the value of server has exactly two items, as it is technically possible to form an incorrect parameter. For example:

    fake_dlmgr.set_proxy_settings(session, 3, (None,))

To address these corner cases, I have to rewrite the function completely. Additional tests have also been added to highlight and test this possibility.

@drew2a drew2a requested a review from xoriole May 23, 2024 11:36
@drew2a drew2a merged commit 0bce76e into Tribler:main May 24, 2024
20 checks passed
@drew2a drew2a deleted the fix/8014 branch May 24, 2024 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[7.14.0] ValueError: invalid literal for int() with base 10 (in DownloadManager.set_proxy_settings)
2 participants