Mercurial > kallithea
changeset 8282:352056907cfd
validators: introduce InvalidCloneUriException instead of throwing bare Exceptions for invalid clone URIs
When adding a new repository with a remote clone URI, the URI will be validated
in some way. In case of errors, it would raise 'Exception' to report invalid
URLs. Code calling the validation would thus have to catch 'Exception', which
means that _any_ exception would cause the URI to be found invalid.
Instead, create a special exception type intended to be used for all exceptions
we know can occur during normal URL validation.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Sun, 01 Mar 2020 21:40:32 +0100 |
parents | 5661a603cf50 |
children | 5b8678cf4e00 |
files | kallithea/lib/exceptions.py kallithea/lib/utils.py |
diffstat | 2 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/exceptions.py Fri Mar 06 18:47:29 2020 +0100 +++ b/kallithea/lib/exceptions.py Sun Mar 01 21:40:32 2020 +0100 @@ -76,3 +76,6 @@ class HgsubversionImportError(Exception): pass + +class InvalidCloneUriException(Exception): + pass
--- a/kallithea/lib/utils.py Fri Mar 06 18:47:29 2020 +0100 +++ b/kallithea/lib/utils.py Sun Mar 01 21:40:32 2020 +0100 @@ -39,7 +39,7 @@ from tg.i18n import ugettext as _ import kallithea.config.conf -from kallithea.lib.exceptions import HgsubversionImportError +from kallithea.lib.exceptions import HgsubversionImportError, InvalidCloneUriException from kallithea.lib.utils2 import ascii_bytes, aslist, get_current_authuser, safe_bytes, safe_str from kallithea.lib.vcs.backends.git.repository import GitRepository from kallithea.lib.vcs.backends.hg.repository import MercurialRepository @@ -225,7 +225,8 @@ def is_valid_repo_uri(repo_type, url, ui): - """Check if the url seems like a valid remote repo location - raise an Exception if any problems""" + """Check if the url seems like a valid remote repo location + Raise InvalidCloneUriException or other Exception if any problems""" if repo_type == 'hg': if url.startswith('http') or url.startswith('ssh'): # initially check if it's at least the proper URL @@ -241,7 +242,7 @@ elif url.startswith('git+http'): raise NotImplementedError() else: - raise Exception('URI %s not allowed' % (url,)) + raise InvalidCloneUriException('URI %s not allowed' % (url,)) elif repo_type == 'git': if url.startswith('http') or url.startswith('git'): @@ -253,7 +254,7 @@ elif url.startswith('hg+http'): raise NotImplementedError() else: - raise Exception('URI %s not allowed' % (url)) + raise InvalidCloneUriException('URI %s not allowed' % (url)) def is_valid_repo(repo_name, base_path, scm=None):