[BUG] failure of find_branch causes Branch.__str__ to be called on a half-constructed branch.

John Arbash Meinel john at arbash-meinel.com
Thu May 26 15:36:47 BST 2005


Aaron Bentley wrote:

> Hi,
>
> This command fails when .be does not exist:
>
> abentley at troll:~/bzrtools2$ bzr remove .be
> bzr: error: u'/home/abentley/bzrtools2/.be' does not exist
> ~  at /home/abentley/bzr.dev/bzrlib/branch.py:64 in find_branch_root()
> ~  see ~/.bzr.log for debug information
> abentley at troll:~/bzrtools2$ bzr remove .be
> bzr: error: u'/home/abentley/bzrtools2/.be' does not exist
> Traceback (most recent call last):
> ~  File "/home/abentley/bin/bzr", line 47, in ?
> ~    sys.exit(bzrlib.commands.main(sys.argv))
> ~  File "/home/abentley/bzr.dev/bzrlib/commands.py", line 1210, in main
> ~    _report_exception('error: ' + e.args[0], quiet=quiet)
> ~  File "/home/abentley/bzr.dev/bzrlib/commands.py", line 1185, in
> _report_exception
> ~    bzrlib.trace.log_exception()
> ~  File "/home/abentley/bzr.dev/bzrlib/trace.py", line 139, in
> log_exception
> ~    s = cgitb.text(sys.exc_info())
> ~  File "/home/abentley//lib/python2.3/cgitb.py", line 190, in text
> ~    formatvalue=lambda value: '=' + pydoc.text.repr(value))
> ~  File "/home/abentley//lib/python2.3/inspect.py", line 725, in
> formatargvalues
> ~    specs.append(strseq(args[i], convert, join))
> ~  File "/home/abentley//lib/python2.3/inspect.py", line 680, in strseq
> ~    return convert(object)
> ~  File "/home/abentley//lib/python2.3/inspect.py", line 722, in convert
> ~    return formatarg(name) + formatvalue(locals[name])
> ~  File "/home/abentley//lib/python2.3/cgitb.py", line 190, in <lambda>
> ~    formatvalue=lambda value: '=' + pydoc.text.repr(value))
> ~  File "/home/abentley//lib/python2.3/repr.py", line 18, in repr
> ~    return self.repr1(x, self.maxlevel)
> ~  File "/home/abentley//lib/python2.3/pydoc.py", line 881, in repr1
> ~    return cram(stripid(repr(x)), self.maxother)
> ~  File "/home/abentley/bzr.dev/bzrlib/branch.py", line 126, in __str__
> ~    return '%s(%r)' % (self.__class__.__name__, self.base)
> AttributeError: 'Branch' object has no attribute 'base'
>
> This can be fixed by initializing Branch.base to None, although that's
> almost certainly the wrong fix:
>
> *** modified file 'bzrlib/branch.py'
> --- bzrlib/branch.py
> +++ bzrlib/branch.py
> @@ -107,6 +107,7 @@
> ~             self.base = os.path.realpath(base)
> ~             self._make_control()
> ~         elif find_root:
> +            self.base = None
> ~             self.base = find_branch_root(base)
> ~         else:
> ~             self.base = os.path.realpath(base)


I believe the specific issue here is that the exception handler does a
reverse inspection to give you extra information about what happened. I
would probably argue that 'self.base' should be initialized to None much
earlier, perhaps even in the class definition.

John
=:->

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050526/49bc8e31/attachment.pgp 


More information about the bazaar mailing list