Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion shell/contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import requests
from PIL import Image

REQUEST_TIMEOUT_SECONDS = 10
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Self-review: Keeping the timeout as a named constant makes it easy to tune later and avoids leaving a maintenance script blocked indefinitely on one slow avatar response.



def main(directory):
contributors = []
Expand Down Expand Up @@ -38,7 +40,10 @@ def main(directory):

for index, contributor in enumerate(contributors):
file_name = os.path.join(directory, str(index) + ".jpeg")
response = requests.get(contributor["avatar_url"])
response = requests.get(
contributor["avatar_url"], timeout=REQUEST_TIMEOUT_SECONDS
)
Comment on lines +43 to +45
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While adding a timeout is a good practice to prevent the script from hanging, it's also important to ensure the request was successful before processing the response. Adding response.raise_for_status() will cause the script to fail with a clear HTTP error if the avatar download fails (e.g., 404 or 500), which is consistent with the 'fail fast' goal of this PR.

Suggested change
response = requests.get(
contributor["avatar_url"], timeout=REQUEST_TIMEOUT_SECONDS
)
response = requests.get(
contributor["avatar_url"], timeout=REQUEST_TIMEOUT_SECONDS
)
response.raise_for_status()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, accepted in 1e1baef by adding response.raise_for_status() after the avatar request.

response.raise_for_status()
file = open(file_name, "wb")
file.write(response.content)
file.close()
Expand Down