Mercurial > public > mercurial-scm > hg
diff mercurial/hg.py @ 41484:7f366dd3df1f
hg: raise Abort on invalid path
Currently, some os.path functions when opening repositories may
raise an uncaught TypeError or ValueError if the path is invalid.
Let's catch these exceptions and turn them into an Abort for
convenience.
Differential Revision: https://phab.mercurial-scm.org/D5772
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 30 Jan 2019 17:22:07 -0800 |
parents | bc843e251134 |
children | 2a3c0106ded9 |
line wrap: on
line diff
--- a/mercurial/hg.py Wed Jan 30 19:29:32 2019 -0500 +++ b/mercurial/hg.py Wed Jan 30 17:22:07 2019 -0800 @@ -38,6 +38,7 @@ narrowspec, node, phases, + pycompat, repository as repositorymod, scmutil, sshpeer, @@ -57,7 +58,15 @@ def _local(path): path = util.expandpath(util.urllocalpath(path)) - return (os.path.isfile(path) and bundlerepo or localrepo) + + try: + isfile = os.path.isfile(path) + # Python 2 raises TypeError, Python 3 ValueError. + except (TypeError, ValueError) as e: + raise error.Abort(_('invalid path %s: %s') % ( + path, pycompat.bytestr(e))) + + return isfile and bundlerepo or localrepo def addbranchrevs(lrepo, other, branches, revs): peer = other.peer() # a courtesy to callers using a localrepo for other