Bzr crashes when running windows native on Cygwin to create a branch

Bug #70565 reported by Nicholas Allen
2
Affects Status Importance Assigned to Milestone
Bazaar
Confirmed
Medium
Unassigned

Bug Description

If I branch from a location to create a new branch using the windows native exe inside a cygwin prompt then bzr displays the following (note if I run inside a DOS prompt it works):

bzr: ERROR: exceptions.TypeError: encode() argument 1 must be string, not None

Traceback (most recent call last):
  File "bzrlib\commands.pyc", line 623, in run_bzr_catch_errors
  File "bzrlib\commands.pyc", line 585, in run_bzr
  File "bzrlib\commands.pyc", line 291, in run_argv_aliases
  File "bzrlib\builtins.pyc", line 685, in run
  File "bzrlib\branch.pyc", line 118, in open
  File "bzrlib\bzrdir.pyc", line 495, in open
  File "bzrlib\bzrdir.pyc", line 504, in open_from_transport
  File "bzrlib\bzrdir.pyc", line 1054, in find_format
  File "bzrlib\bzrdir.pyc", line 1064, in probe_transport
  File "bzrlib\transport\ftp.pyc", line 268, in get
  File "bzrlib\transport\ftp.pyc", line 141, in _get_FTP
  File "bzrlib\transport\ftp.pyc", line 72, in _find_FTP
  File "bzrlib\ui\text.pyc", line 85, in get_password
TypeError: encode() argument 1 must be string, not None

bzr 0.12.0 on python 2.4.4.final.0 (win32)

Tags: cygwin
Revision history for this message
John A Meinel (jameinel) wrote :

This should be pretty easy to fix. The problem is that on Cygwin sys.stdout doesn't seem to be getting a proper encoding value. We have a function that is supposed to be used for this:

osutils.get_terminal_encoding()

This patch should fix it:
=== modified file 'bzrlib/ui/text.py'
--- bzrlib/ui/text.py 2006-10-31 01:30:31 +0000
+++ bzrlib/ui/text.py 2006-11-06 17:14:08 +0000
@@ -82,7 +82,10 @@
         :return: The password string, return None if the user
                  canceled the request.
         """
- prompt = (prompt % kwargs).encode(sys.stdout.encoding, 'replace')
+ # prompt = (prompt % kwargs).encode(sys.stdout.encoding, 'replace')
+ encoding = osutils.get_terminal_encoding()
+ prompt = (prompt % kwargs)
+ prompt = prompt.encode(encoding, 'replace')
         prompt += ': '
         # There's currently no way to say 'i decline to enter a password'
         # as opposed to 'my password is empty' -- does it matter?

Also, it wouldn't be terribly hard to write a test for this. You just override sys.stdout with a StringIO() object, which doesn't have a .encoding attribute. (Use a try/finally to make sure to restore the original sys.stdout).

Alternatively, you can use the bzrlib.tests.StringIOWrapper() which adds a .encoding attribute to StringIO, and set it to None.

Also, we would need to override getpass.getpass() so that we don't actually try to prompt the user on the terminal. We may want to refactor getpass() so that it is called from a member of TextUIFactory, so we can subclass for testing.

Nick: Can you test the patch and see if it works, before we spend too much time writing tests, etc.

Changed in bzr:
importance: Undecided → Medium
status: Unconfirmed → Confirmed
Revision history for this message
Nicholas Allen (nick-allen) wrote :

Sure no problem. I'll check it tomorrow as I don't have access to Cygwin at home...

Revision history for this message
Alexander Belchenko (bialix) wrote : Re: [Bug 70565] Bzr crashes when running windows native on Cygwin to create a branch

Nicholas Allen пишет:
> Public bug reported:
>
> If I branch from a location to create a new branch using the windows
> native exe inside a cygwin prompt then bzr displays the following (note
> if I run inside a DOS prompt it works):
>
> bzr: ERROR: exceptions.TypeError: encode() argument 1 must be string,
> not None

I wonder why you are using native windows bzr.exe inside cygwin instead
of cygwin one.

Revision history for this message
Nicholas Allen (nick-allen) wrote :

The native client performs much better than the cygwin one and I prefer cygwin over the dos prompt.

Revision history for this message
Nicholas Allen (nick-allen) wrote :

Hi John,

Sorry for the silly question but in trying to run the patched bzr sources inside the cygwin prompt using the native windows python I am unable to get python to recognize bzr on its path. I have set PYTHONPATH in the system environment variables to include the bzr-0.12 directory and I have even tried setting the environment variable from within cygwin too but it never seems to find the osutils module which is inside the bzr dir.

I do this inside the cygwin prompt:

/c/Python25/Scripts/bzr.bat pull

but it always complains:

bzr: ERROR: exceptions.NameError: global name 'osutils' is not defined

Traceback (most recent call last):
  File "C:\bzr-0.12\bzrlib\commands.py", line 623, in run_bzr_catch_errors
    return run_bzr(argv)
  File "C:\bzr-0.12\bzrlib\commands.py", line 585, in run_bzr
    ret = run(*run_argv)
  File "C:\bzr-0.12\bzrlib\commands.py", line 291, in run_argv_aliases
    return self.run(**all_cmd_args)
  File "C:\bzr-0.12\bzrlib\builtins.py", line 511, in run
    branch_from = Branch.open(location)
  File "C:\bzr-0.12\bzrlib\branch.py", line 118, in open
    control = bzrdir.BzrDir.open(base, _unsupported)
  File "C:\bzr-0.12\bzrlib\bzrdir.py", line 495, in open
    return BzrDir.open_from_transport(t, _unsupported=_unsupported)
  File "C:\bzr-0.12\bzrlib\bzrdir.py", line 504, in open_from_transport
    format = BzrDirFormat.find_format(transport)
  File "C:\bzr-0.12\bzrlib\bzrdir.py", line 1054, in find_format
    return format.probe_transport(transport)
  File "C:\bzr-0.12\bzrlib\bzrdir.py", line 1064, in probe_transport
    format_string = transport.get(".bzr/branch-format").read()
  File "c:\bzr-0.12\bzrlib\transport\ftp.py", line 268, in get
    f = self._get_FTP()
  File "c:\bzr-0.12\bzrlib\transport\ftp.py", line 141, in _get_FTP
    self.is_active)
  File "c:\bzr-0.12\bzrlib\transport\ftp.py", line 72, in _find_FTP
    user=username, host=hostname)
  File "c:\bzr-0.12\bzrlib\ui\text.py", line 86, in get_password
    encoding = osutils.get_terminal_encoding()
NameError: global name 'osutils' is not defined

bzr 0.12.0 on python 2.5.0.final.0 (win32)
arguments: ['c:\\Python25\\Scripts\\bzr', 'pull']

Revision history for this message
John A Meinel (jameinel) wrote :

Is this still a problem, sorry about the delayed response...

This is probably a better patch. If it fixes your problem, we should merge this into bzr.

=== modified file 'bzrlib/ui/text.py'
--- bzrlib/ui/text.py 2006-10-31 01:30:31 +0000
+++ bzrlib/ui/text.py 2007-01-03 21:19:52 +0000
@@ -26,6 +26,7 @@
 import getpass

 from bzrlib import (
+ osutils,
     progress,
     )
 """)
@@ -82,7 +83,8 @@
         :return: The password string, return None if the user
                  canceled the request.
         """
- prompt = (prompt % kwargs).encode(sys.stdout.encoding, 'replace')
+ encoding = osutils.get_terminal_encoding()
+ prompt = (prompt % kwargs).encode(encoding, 'replace')
         prompt += ': '
         # There's currently no way to say 'i decline to enter a password'
         # as opposed to 'my password is empty' -- does it matter?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.