Skip to content

Commit

Permalink
improve logging in case of exception
Browse files Browse the repository at this point in the history
remove try..except cascade and add traceback information
  • Loading branch information
mampfes committed Feb 20, 2022
1 parent 3cf5306 commit 191116d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
5 changes: 1 addition & 4 deletions custom_components/waste_collection_schedule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@ def add_scraper(self, source_name, customize, source_args, calendar_title):

def _fetch(self, *_):
for scraper in self._scrapers:
try:
scraper.fetch()
except Exception as error:
_LOGGER.error(f"fetch failed for source {scraper.source}: {error}")
scraper.fetch()

self._update_sensors_callback()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import importlib
import itertools
import logging
import traceback
from typing import Dict, List, Optional

from .collection import Collection, CollectionGroup
Expand Down Expand Up @@ -113,21 +114,24 @@ def fetch(self):
try:
# fetch returns a list of Collection's
entries = self._source.fetch()
self._refreshtime = datetime.datetime.now()
except Exception:
_LOGGER.error(
f"fetch failed for source {self._title}:\n{traceback.format_exc()}"
)
return
self._refreshtime = datetime.datetime.now()

# strip whitespaces
for e in entries:
e.set_type(e.type.strip())
# strip whitespaces
for e in entries:
e.set_type(e.type.strip())

# filter hidden entries
entries = filter(lambda x: filter_function(x, self._customize), entries)
# filter hidden entries
entries = filter(lambda x: filter_function(x, self._customize), entries)

# customize fetched entries
entries = map(lambda x: customize_function(x, self._customize), entries)
# customize fetched entries
entries = map(lambda x: customize_function(x, self._customize), entries)

self._entries = list(entries)
except Exception as error:
_LOGGER.error(f"fetch failed for source {self._source}: {error}")
self._entries = list(entries)

def get_types(self):
"""Return set() of all collection types."""
Expand Down

0 comments on commit 191116d

Please sign in to comment.