[MERGE] Catch KeyError from pwd.getpwuid(uid) [was: Re: Pulling pretty big revision...]

Andrew Bennetts andrew.bennetts at canonical.com
Thu Oct 30 22:52:29 GMT 2008


Robert Collins wrote:
> I think its a machine configuration issue - that uid is not mappable to
> a username on your machine; if you're using ldap or something this could
> indicate a network failure happened.

That said we could fail more gracefully here.  The obvious patch would seem to
be:

=== modified file 'bzrlib/config.py'
--- bzrlib/config.py	2008-10-16 18:30:32 +0000
+++ bzrlib/config.py	2008-10-30 22:50:51 +0000
@@ -839,7 +839,11 @@
     try:
         import pwd
         uid = os.getuid()
-        w = pwd.getpwuid(uid)
+        try:
+            w = pwd.getpwuid(uid)
+        except KeyError:
+            raise errors.BzrCommandError('Unable to determine your name.  '
+               'Use "bzr whoami" to set it.')
 
         # we try utf-8 first, because on many variants (like Linux),
         # /etc/passwd "should" be in utf-8, and because it's unlikely to give


-Andrew.




More information about the bazaar mailing list