mirror of https://github.com/caronc/apprise
Better logging when a URL can not be parsed (#257)
parent
70b3f51f6a
commit
74759031fc
|
@ -111,14 +111,10 @@ class Apprise(object):
|
||||||
# Acquire our url tokens
|
# Acquire our url tokens
|
||||||
results = plugins.url_to_dict(url)
|
results = plugins.url_to_dict(url)
|
||||||
if results is None:
|
if results is None:
|
||||||
# Failed to parse the server URL
|
# Failed to parse the server URL; detailed logging handled
|
||||||
logger.error('Unparseable URL {}.'.format(url))
|
# inside url_to_dict - nothing to report here.
|
||||||
return None
|
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):
|
elif isinstance(url, dict):
|
||||||
# We already have our result set
|
# We already have our result set
|
||||||
results = url
|
results = url
|
||||||
|
@ -154,11 +150,14 @@ class Apprise(object):
|
||||||
plugin = plugins.SCHEMA_MAP[results['schema']](**results)
|
plugin = plugins.SCHEMA_MAP[results['schema']](**results)
|
||||||
|
|
||||||
# Create log entry of loaded URL
|
# 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:
|
except Exception:
|
||||||
# the arguments are invalid or can not be used.
|
# 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
|
return None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -226,7 +225,7 @@ class Apprise(object):
|
||||||
# returns None if it fails
|
# returns None if it fails
|
||||||
instance = Apprise.instantiate(_server, asset=asset, tag=tag)
|
instance = Apprise.instantiate(_server, asset=asset, tag=tag)
|
||||||
if not isinstance(instance, NotifyBase):
|
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
|
# and/or success reasons for us
|
||||||
return_status = False
|
return_status = False
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -422,11 +422,6 @@ class ConfigBase(URLBase):
|
||||||
# notifications if any were set
|
# notifications if any were set
|
||||||
results['tag'] = set(parse_list(result.group('tags')))
|
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
|
# Prepare our Asset Object
|
||||||
results['asset'] = \
|
results['asset'] = \
|
||||||
asset if isinstance(asset, AppriseAsset) else AppriseAsset()
|
asset if isinstance(asset, AppriseAsset) else AppriseAsset()
|
||||||
|
|
|
@ -23,11 +23,11 @@
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
|
import os
|
||||||
import six
|
import six
|
||||||
import re
|
import re
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from os import listdir
|
|
||||||
from os.path import dirname
|
from os.path import dirname
|
||||||
from os.path import abspath
|
from os.path import abspath
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ from ..common import NotifyType
|
||||||
from ..common import NOTIFY_TYPES
|
from ..common import NOTIFY_TYPES
|
||||||
from ..utils import parse_list
|
from ..utils import parse_list
|
||||||
from ..utils import GET_SCHEMA_RE
|
from ..utils import GET_SCHEMA_RE
|
||||||
|
from ..logger import logger
|
||||||
from ..AppriseLocale import gettext_lazy as _
|
from ..AppriseLocale import gettext_lazy as _
|
||||||
from ..AppriseLocale import LazyTranslation
|
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
|
# 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)
|
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)
|
match = module_re.match(f)
|
||||||
if not match:
|
if not match:
|
||||||
# keep going
|
# keep going
|
||||||
|
@ -452,6 +453,7 @@ def url_to_dict(url):
|
||||||
schema = GET_SCHEMA_RE.match(_url)
|
schema = GET_SCHEMA_RE.match(_url)
|
||||||
if schema is None:
|
if schema is None:
|
||||||
# Not a valid URL; take an early exit
|
# Not a valid URL; take an early exit
|
||||||
|
logger.error('Unparseable URL {}.'.format(url))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Ensure our schema is always in lower case
|
# Ensure our schema is always in lower case
|
||||||
|
@ -466,10 +468,28 @@ def url_to_dict(url):
|
||||||
for r in MODULE_MAP.values()
|
for r in MODULE_MAP.values()
|
||||||
if r['plugin'].parse_native_url(_url) is not None),
|
if r['plugin'].parse_native_url(_url) is not None),
|
||||||
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:
|
else:
|
||||||
# Parse our url details of the server object as dictionary
|
# Parse our url details of the server object as dictionary
|
||||||
# containing all of the information parsed from our URL
|
# containing all of the information parsed from our URL
|
||||||
results = SCHEMA_MAP[schema].parse_url(_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 our results
|
||||||
return results
|
return results
|
||||||
|
|
Loading…
Reference in New Issue