Python publish script silently crashed on timeouts despite having error handling
A developer discovered that publish_devto.py, a script used to automate article publishing to DEV.to, had a critical gap in its exception handling. The script caught urllib.error.HTTPError for failed HTTP responses but did not handle urllib.error.URLError, the broader parent class that covers timeouts, DNS failures, and refused connections. This meant that despite the script explicitly setting a 30-second timeout, a network timeout would cause an unhandled exception rather than a clean, informative exit. The bug went unnoticed through multiple code reviews because the presence of any error handling led reviewers to assume coverage was complete. The fix required adding a second except clause for URLError, ordered below the narrower HTTPError catch to respect Python's top-to-bottom exception matching.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in