Skip to content

Commit

Permalink
Fixed: Connection errors are properly recognised
Browse files Browse the repository at this point in the history
  • Loading branch information
mnot committed Nov 5, 2023
1 parent 9250f0d commit 1a909a0
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions redbot/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ def __init__(self, config: SectionProxy, descend: bool = False) -> None:
self.subreqs = {ac.check_name: ac(config, self) for ac in active_checks}
self.once("fetch_done", self.run_active_checks)

def _finish_check() -> None:
self.finish_check(None)

self.on("fetch_done", _finish_check)
self.links: Dict[str, Set[str]] = {}
self.link_count: int = 0
self.linked: List[Tuple[HttpResource, str]] = [] # linked HttpResources
Expand All @@ -64,8 +60,6 @@ def _finish_check() -> None:
)
self.response_content_processors.append(self._link_parser.feed_bytes)

# self.show_task_map(True) # for debugging

def run_active_checks(self) -> None:
"""
Response is available; perform subordinate requests (e.g., conneg check).
Expand All @@ -74,6 +68,8 @@ def run_active_checks(self) -> None:
for active_check in list(self.subreqs.values()):
self.add_check(active_check)
active_check.check()
else:
self.finish_check()

def add_check(self, *resources: RedFetcher) -> None:
"Remember a subordinate check on one or more HttpResource instance."
Expand All @@ -95,14 +91,15 @@ def check_done() -> None:

# pylint: enable=cell-var-from-loop

def finish_check(self, resource: RedFetcher) -> None:
def finish_check(self, resource: RedFetcher = None) -> None:
"A check is done. Was that the last one?"
try:
self._task_map.remove(resource)
except KeyError:
raise KeyError( # pylint: disable=raise-missing-from
f"* Can't find {resource} in task map: {self._task_map}"
)
if resource:
try:
self._task_map.remove(resource)
except KeyError:
raise KeyError( # pylint: disable=raise-missing-from
f"* Can't find {resource} in task map: {self._task_map}"
)
tasks_left = len(self._task_map)
# self.emit("debug", "%s checks remaining: %i" % (repr(self), tasks_left))
if tasks_left == 0:
Expand Down

0 comments on commit 1a909a0

Please sign in to comment.