aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'webmentions_ssg/tasks')
-rw-r--r--webmentions_ssg/tasks/discovery.py11
-rw-r--r--webmentions_ssg/tasks/receiver.py3
-rw-r--r--webmentions_ssg/tasks/sender.py12
3 files changed, 19 insertions, 7 deletions
diff --git a/webmentions_ssg/tasks/discovery.py b/webmentions_ssg/tasks/discovery.py
index 29c3e81..456e47e 100644
--- a/webmentions_ssg/tasks/discovery.py
+++ b/webmentions_ssg/tasks/discovery.py
@@ -11,7 +11,12 @@ import httpx
from bs4 import BeautifulSoup
from flask import current_app
-from ..net import is_http_url, is_temporary_status, read_limited_body
+from ..net import (
+ ResponseTooLargeError,
+ is_http_url,
+ is_temporary_status,
+ read_limited_body,
+)
LINK_SPLIT = re.compile(r",\s*(?=<)")
DISCOVERY_HEADERS = {"Accept": "text/html, application/xhtml+xml;q=0.9"}
@@ -130,7 +135,7 @@ def read_target_body(response: httpx.Response) -> bytes:
return read_limited_body(
response, current_app.config["MAX_TARGET_BYTES"], label="Target"
)
- except ValueError as exc:
+ except ResponseTooLargeError as exc:
raise PermanentSenderError(str(exc)) from exc
@@ -149,7 +154,7 @@ def discover_webmention_endpoint(client: httpx.Client, target: str) -> str | Non
"""
try:
head_response = client.head(target, headers=DISCOVERY_HEADERS)
- except httpx.RequestError, TemporarySenderError:
+ except httpx.RequestError:
# HEAD is only an optimization. Servers and intermediaries may reject
# or drop it even when fetching the document with GET would succeed.
pass
diff --git a/webmentions_ssg/tasks/receiver.py b/webmentions_ssg/tasks/receiver.py
index 2963dc7..cbb42b6 100644
--- a/webmentions_ssg/tasks/receiver.py
+++ b/webmentions_ssg/tasks/receiver.py
@@ -16,6 +16,7 @@ from ..extensions import db, huey
from ..models import ReceivedStatus, ReceivedWebmention
from ..net import (
AddressResolutionError,
+ ResponseTooLargeError,
UnsafeAddressError,
build_client,
is_temporary_status,
@@ -76,7 +77,7 @@ def fetch_source(source_url: str) -> tuple[httpx.Response, bytes]:
return response, read_limited_body(
response, current_app.config["MAX_SOURCE_BYTES"], label="Source"
)
- except ValueError as exc:
+ except ResponseTooLargeError as exc:
raise VerificationError(str(exc)) from exc
except UnsafeAddressError as exc:
diff --git a/webmentions_ssg/tasks/sender.py b/webmentions_ssg/tasks/sender.py
index db99476..cd6c64a 100644
--- a/webmentions_ssg/tasks/sender.py
+++ b/webmentions_ssg/tasks/sender.py
@@ -210,10 +210,8 @@ def send_webmention_task(webmention_uuid: uuid.UUID) -> None:
httpx.InvalidURL,
httpx.UnsupportedProtocol,
httpx.LocalProtocolError,
- ValueError,
- UnicodeError,
) as exc:
- # Invalid URLs and local protocol errors cannot improve with retries.
+ # Known permanent failures cannot improve with retries.
outcome = SentWebmentionStatus.FAILED
reason = str(exc) or type(exc).__name__
except (TemporarySenderError, AddressResolutionError, httpx.RequestError) as exc:
@@ -221,6 +219,14 @@ def send_webmention_task(webmention_uuid: uuid.UUID) -> None:
reason = str(exc) or "Webmention request failed"
terminal = attempt >= max_attempts
temporary_failure = True
+ except Exception as exc:
+ # Unexpected errors must not disappear into a generic permanent-failure
+ # handler without a traceback (including programming ValueErrors).
+ current_app.logger.exception(
+ "Unexpected error sending SentWebmention %s", webmention_uuid
+ )
+ outcome = SentWebmentionStatus.FAILED
+ reason = str(exc) or type(exc).__name__
# A scanner may have reopened or superseded the revision during I/O.
# Refresh only once, and persist one outcome atomically with its metadata.