Skip to content

Commit 21a883b

Browse files
authored
Merge pull request #123 from TotallyNotRobots/gonzobot+requests-error-warning
Make link_announcer only log when it errors, not raise
2 parents e66a240 + e3d6d2d commit 21a883b

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

.github/workflows/pythonapp.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ jobs:
4747
PYTHONASYNCIODEBUG: ${{ matrix.asyncio-debug }}
4848
PYTHONPATH: .
4949
- uses: codecov/codecov-action@v1
50+
with:
51+
name: build-${{ matrix.python-ver}}-${{ matrix.asyncio-debug }}
52+
fail_ci_if_error: true

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- Add Python 3.8 to testing matrix
1010
### Changed
1111
- Refactor tests to remove dependency on mock library
12+
- Change link_announcer.py to only warn on connection errors
1213
### Fixed
1314
- Fix matching exception in horoscope test
1415
- Fix youtube.py ISO time parse
File renamed without changes.

plugins/link_announcer.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ def no_parens(pattern):
2323
r"""
2424
https? # Scheme
2525
://
26-
26+
2727
# Username and Password
2828
(?:
2929
(?:[^\[\]?/<~#`!@$%^&*()=+}|:";',>{\s]|%[0-9A-F]{2})*
3030
(?::(?:[^\[\]?/<~#`!@$%^&*()=+}|:";',>{\s]|%[0-9A-F]{2})*)?
3131
@
3232
)?
33-
33+
3434
# Domain
3535
(?:
3636
# TODO Add support for IDNA hostnames as specified by RFC5891
@@ -41,13 +41,13 @@ def no_parens(pattern):
4141
)
4242
(?<![.,?!\]]) # Invalid end chars
4343
)
44-
44+
4545
(?::\d*)? # port
46-
46+
4747
(?:/(?:""" + no_parens(PATH_SEG_CHARS) + r""")*(?<![.,?!\]]))* # Path segment
48-
48+
4949
(?:\?(?:""" + no_parens(QUERY_CHARS) + r""")*(?<![.,!\]]))? # Query
50-
50+
5151
(?:\#(?:""" + no_parens(FRAG_CHARS) + r""")*(?<![.,?!\]]))? # Fragment
5252
""",
5353
re.IGNORECASE | re.VERBOSE
@@ -98,9 +98,12 @@ def print_url_title(message, match, logger):
9898

9999
content = r.raw.read(MAX_RECV, decode_content=True)
100100
encoding = r.encoding
101-
except requests.ReadTimeout:
101+
except requests.exceptions.ReadTimeout:
102102
logger.debug("Read timeout reached for %r", match.group())
103103
return
104+
except requests.ConnectionError:
105+
logger.warning("Connection error in link_announcer.py", exc_info=1)
106+
return
104107

105108
html = parse_content(content, encoding)
106109

tests/plugin_tests/test_link_announcer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,16 @@ def callback(resp):
239239
def test_change_encoding(body, encoding):
240240
# ISO-8859-1 is the default encoding requests would return if none is found
241241
assert parse_content(body, 'ISO-8859-1').original_encoding == encoding
242+
243+
244+
def test_connection_error(mock_requests):
245+
url = "http://example.com"
246+
247+
match = url_re.search(url)
248+
assert match
249+
mck = MagicMock()
250+
logger = MagicMock()
251+
252+
assert print_url_title(match=match, message=mck, logger=logger) is None
253+
254+
assert logger.warning.called

0 commit comments

Comments
 (0)