Mercurial > hg-stable
comparison mercurial/hg.py @ 25365:4cc3fb23881d
hg: explicitly check that peer lookup object has instance() if call failed
If a "thing" is callable but raises TypeError for some reason, a callable
object would be returned. Thereafter, unfriendly traceback would be displayed:
Traceback (most recent call last):
...
File "mercurial/hg.pyc", line 119, in _peerorrepo
obj = _peerlookup(path).instance(ui, path, create)
AttributeError: 'function' object has no attribute 'instance'
Instead, we should show the reason why "thing(path)" didn't work:
Traceback (most recent call last):
...
File "hggit/__init__.py", line 89, in _local
p = urlcls(path).localpath()
TypeError: 'NoneType' object is not callable
If a "thing" is not callable, it must be a module or an object that implements
instance(). If that module didn't have instance(), the error message would be
"<unloaded module 'foo'> object is not callable". It doesn't make perfect sense,
but it isn't so bad as it can blame which module went wrong.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 30 May 2015 12:46:30 +0900 |
parents | e0b0fbd47491 |
children | f1d46075b13a |
comparison
equal
deleted
inserted
replaced
25364:de23a552fc23 | 25365:4cc3fb23881d |
---|---|
90 scheme = u.scheme or 'file' | 90 scheme = u.scheme or 'file' |
91 thing = schemes.get(scheme) or schemes['file'] | 91 thing = schemes.get(scheme) or schemes['file'] |
92 try: | 92 try: |
93 return thing(path) | 93 return thing(path) |
94 except TypeError: | 94 except TypeError: |
95 # we can't test callable(thing) because 'thing' can be an unloaded | |
96 # module that implements __call__ | |
97 if not util.safehasattr(thing, 'instance'): | |
98 raise | |
95 return thing | 99 return thing |
96 | 100 |
97 def islocal(repo): | 101 def islocal(repo): |
98 '''return true if repo (or path pointing to repo) is local''' | 102 '''return true if repo (or path pointing to repo) is local''' |
99 if isinstance(repo, str): | 103 if isinstance(repo, str): |