tomerfiliba / plumbum

Plumbum: Shell Combinators
https://plumbum.readthedocs.io
MIT License
2.82k stars 184 forks source link

ProcessExecutionError is misleading when piped commands fail #241

Closed hashbrowncipher closed 9 years ago

hashbrowncipher commented 9 years ago

Relates to #145

Type "help", "copyright", "credits" or "license" for more information.
>>> from plumbum.cmd import cat, head
>>> from plumbum import FG
>>> (cat['/dev/urndom'] | head['-c', '10']) & FG()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nail/home/josnyder/consul-backups/env/local/lib/python2.7/site-packages/plumbum/commands/modifiers.py", line 143, in __rand__
    cmd(retcode = self.retcode, stdin = None, stdout = None, stderr = None)
  File "/nail/home/josnyder/consul-backups/env/local/lib/python2.7/site-packages/plumbum/commands/base.py", line 89, in __call__
    return self.run(args, **kwargs)[1]
  File "/nail/home/josnyder/consul-backups/env/local/lib/python2.7/site-packages/plumbum/commands/base.py", line 219, in run
    return p.run()
  File "/nail/home/josnyder/consul-backups/env/local/lib/python2.7/site-packages/plumbum/commands/base.py", line 181, in runner
    return run_proc(p, retcode, timeout)
  File "/nail/home/josnyder/consul-backups/env/local/lib/python2.7/site-packages/plumbum/commands/processes.py", line 217, in run_proc
    return _check_process(proc, retcode, timeout, stdout, stderr)
  File "/nail/home/josnyder/consul-backups/env/local/lib/python2.7/site-packages/plumbum/commands/processes.py", line 34, in _check_process
    stdout, stderr)
plumbum.commands.processes.ProcessExecutionError: Command line: ['/usr/bin/head', '-c', '10']
Exit code: 1

In this example, the process which failed is the cat process. The exception message is misleading, because it implies that the head process failed.

hashbrowncipher commented 9 years ago

@henryiii, I tidied up my original commit into a PR, but I see you've assigned this issue to yourself. If you have a better solution than mine, by all means go for it.

henryiii commented 9 years ago

No, go ahead!