Skip to content

Commit

Permalink
Raise an exception when taskwarrior has a non-zero return status.
Browse files Browse the repository at this point in the history
  • Loading branch information
coddingtonbear committed Feb 14, 2014
1 parent 9031179 commit 8bb3899
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions taskw/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


class TaskwarriorError(Exception):
def __init__(self, stderr, stdout, code):
self.stderr = stderr.strip()
self.stdout = stdout.strip()
self.code = code
super(TaskwarriorError, self).__init__(self.stderr)
9 changes: 7 additions & 2 deletions taskw/warrior.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import pprint

import taskw.utils
from taskw.exceptions import TaskwarriorError

import six
from six import with_metaclass
Expand Down Expand Up @@ -420,11 +421,15 @@ def _execute(self, *args):
'rc.verbose=nothing',
'rc.confirmation=no',
] + [six.text_type(arg) for arg in args]
return subprocess.Popen(
proc = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).communicate()
)
stdout, stderr = proc.communicate()
if proc.returncode != 0:
raise TaskwarriorError(stderr, stdout, proc.returncode)
return stdout, stderr

def _get_json(self, *args):
encoded = self._execute(*args)[0]
Expand Down

0 comments on commit 8bb3899

Please sign in to comment.