New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke Crashes task if a run command tries to print ASCII instead of Unicode #321

Closed
dimacus opened this Issue Feb 5, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@dimacus

dimacus commented Feb 5, 2016

I was helping someone debug a stuck invoke build in Jenkins, where part of the task was to run npm install

def do_npm_install():
    run('npm install')

The build would hang until we upgrade from 0.12.0 to 0.12.1 after this the build got "unstuck" and a new stack trace surfaced:

File "/web/tasks.py", line 49, in do_npm_install
    run('npm install')
  File "/usr/local/lib/python3.5/site-packages/invoke/__init__.py", line 27, in run
    return Context().run(command, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/invoke/context.py", line 53, in run
    return runner_class(context=self).run(command, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/invoke/runners.py", line 270, in run
    raise ThreadException(exceptions)
invoke.exceptions.ThreadException: 
Saw 1 exceptions within threads (UnicodeEncodeError):


Thread args: {'kwargs': {'buffer_': [],
            'hide': False,
            'output': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='ANSI_X3.4-1968'>},
 'target': <bound method Runner.handle_stdout of <invoke.runners.Local object at 0x7f7d8d5f7400>>}

Traceback (most recent call last):

  File "/usr/local/lib/python3.5/site-packages/invoke/runners.py", line 851, in run
    super(_IOThread, self).run()

  File "/usr/local/lib/python3.5/threading.py", line 871, in run
    self._target(*self._args, **self._kwargs)

  File "/usr/local/lib/python3.5/site-packages/invoke/runners.py", line 406, in handle_stdout
    indices=threading.local(),

  File "/usr/local/lib/python3.5/site-packages/invoke/runners.py", line 376, in _handle_output
    output.write(data)

UnicodeEncodeError: 'ascii' codec can't encode characters in position 463-471: ordinal not in range(128)

It seems that npm was trying to print and ASCII charset to STDOUT and Invoke didn't like that. The work around is to pipe stdout and stderr into a text file so Invoke never sees it. However, this bug should probably be fixed.

def do_npm_install():
    run('npm install 2>&1 > npm_install.log')
@bitprophet

This comment has been minimized.

Member

bitprophet commented Feb 8, 2016

Suspecting this is related at least in part to #289 and #274. Hopefully the centralizing of encoding stuff planned in the later comments on #289, and/or an updated version of #274, will address this. Leaving open in case that stuff happens & this is still an issue. Thanks for the feedback!

@bitprophet

This comment has been minimized.

Member

bitprophet commented Jun 3, 2016

This does seem like it falls under #350, so hopefully the behavior is improved once that's released (soon). Please comment after 0.13 comes out if that doesn't fix this for you. Thanks!

@bitprophet bitprophet closed this Jun 3, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment