Better logging when a URL can not be parsed (#257)

This commit is contained in:
Chris Caron 2020-07-24 19:57:24 -04:00 committed by GitHub
parent 70b3f51f6a
commit 74759031fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 16 deletions

View File

@ -111,14 +111,10 @@ class Apprise(object):
# Acquire our url tokens
results = plugins.url_to_dict(url)
if results is None:
# Failed to parse the server URL
logger.error('Unparseable URL {}.'.format(url))
# Failed to parse the server URL; detailed logging handled
# inside url_to_dict - nothing to report here.
return None
logger.trace('URL {} unpacked as:{}{}'.format(
url, os.linesep, os.linesep.join(
['{}="{}"'.format(k, v) for k, v in results.items()])))
elif isinstance(url, dict):
# We already have our result set
results = url
@ -154,11 +150,14 @@ class Apprise(object):
plugin = plugins.SCHEMA_MAP[results['schema']](**results)
# Create log entry of loaded URL
logger.debug('Loaded URL: {}'.format(plugin.url()))
logger.debug('Loaded {} URL: {}'.format(
plugins.SCHEMA_MAP[results['schema']].service_name,
plugin.url()))
except Exception:
# the arguments are invalid or can not be used.
logger.error('Could not load URL: %s' % url)
logger.error('Could not load {} URL: {}'.format(
plugins.SCHEMA_MAP[results['schema']].service_name, url))
return None
else:
@ -226,7 +225,7 @@ class Apprise(object):
# returns None if it fails
instance = Apprise.instantiate(_server, asset=asset, tag=tag)
if not isinstance(instance, NotifyBase):
# No logging is requird as instantiate() handles failure
# No logging is required as instantiate() handles failure
# and/or success reasons for us
return_status = False
continue

View File

@ -422,11 +422,6 @@ class ConfigBase(URLBase):
# notifications if any were set
results['tag'] = set(parse_list(result.group('tags')))
ConfigBase.logger.trace(
'URL {} unpacked as:{}{}'.format(
url, os.linesep, os.linesep.join(
['{}="{}"'.format(k, v) for k, v in results.items()])))
# Prepare our Asset Object
results['asset'] = \
asset if isinstance(asset, AppriseAsset) else AppriseAsset()

View File

@ -23,11 +23,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import os
import six
import re
import copy
from os import listdir
from os.path import dirname
from os.path import abspath
@ -45,6 +45,7 @@ from ..common import NotifyType
from ..common import NOTIFY_TYPES
from ..utils import parse_list
from ..utils import GET_SCHEMA_RE
from ..logger import logger
from ..AppriseLocale import gettext_lazy as _
from ..AppriseLocale import LazyTranslation
@ -85,7 +86,7 @@ def __load_matrix(path=abspath(dirname(__file__)), name='apprise.plugins'):
# The .py extension is optional as we support loading directories too
module_re = re.compile(r'^(?P<name>Notify[a-z0-9]+)(\.py)?$', re.I)
for f in listdir(path):
for f in os.listdir(path):
match = module_re.match(f)
if not match:
# keep going
@ -452,6 +453,7 @@ def url_to_dict(url):
schema = GET_SCHEMA_RE.match(_url)
if schema is None:
# Not a valid URL; take an early exit
logger.error('Unparseable URL {}.'.format(url))
return None
# Ensure our schema is always in lower case
@ -466,10 +468,28 @@ def url_to_dict(url):
for r in MODULE_MAP.values()
if r['plugin'].parse_native_url(_url) is not None),
None)
if not results:
logger.error('Unparseable URL {}.'.format(url))
return None
logger.trace('URL {} unpacked as:{}{}'.format(
url, os.linesep, os.linesep.join(
['{}="{}"'.format(k, v) for k, v in results.items()])))
else:
# Parse our url details of the server object as dictionary
# containing all of the information parsed from our URL
results = SCHEMA_MAP[schema].parse_url(_url)
if not results:
logger.error('Unparseable {} URL {}.'.format(
SCHEMA_MAP[schema].service_name, url))
return None
logger.trace('{} URL {} unpacked as:{}{}'.format(
SCHEMA_MAP[schema].service_name, url,
os.linesep, os.linesep.join(
['{}="{}"'.format(k, v) for k, v in results.items()])))
# Return our results
return results