Skip to content
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

dimacus opened this issue Feb 5, 2016 · 2 comments


Copy link

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/", line 49, in do_npm_install
    run('npm install')
  File "/usr/local/lib/python3.5/site-packages/invoke/", line 27, in run
    return Context().run(command, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/invoke/", line 53, in run
    return runner_class(context=self).run(command, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/invoke/", line 270, in run
    raise ThreadException(exceptions)
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/", line 851, in run
    super(_IOThread, self).run()

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

  File "/usr/local/lib/python3.5/site-packages/invoke/", line 406, in handle_stdout

  File "/usr/local/lib/python3.5/site-packages/invoke/", line 376, in _handle_output

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')
Copy link

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!

Copy link

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!

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

No branches or pull requests

2 participants