Commit aa3f1654 authored by Michal Čihař's avatar Michal Čihař

Improve error handling in VCS module

parent 5ead5b3e
...@@ -34,6 +34,19 @@ class RepositoryException(Exception): ...@@ -34,6 +34,19 @@ class RepositoryException(Exception):
""" """
Error while working with a repository. Error while working with a repository.
""" """
def __init__(self, retcode, stderr, stdout):
self.retcode = retcode
self.stderr = stderr.strip()
self.stdout = stdout.strip()
def __str__(self):
if self.stderr:
message = self.stderr
else:
message = self.stdout
if self.retcode != 0:
return '{0} ({1})'.format(message, self.retcode)
return message
class Repository(object): class Repository(object):
...@@ -87,7 +100,7 @@ class Repository(object): ...@@ -87,7 +100,7 @@ class Repository(object):
Executes the command using popen. Executes the command using popen.
''' '''
if args is None: if args is None:
raise RepositoryException('Not supported functionality') raise RepositoryException(0, 'Not supported functionality', '')
args = [cls._cmd] + args args = [cls._cmd] + args
process = subprocess.Popen( process = subprocess.Popen(
args, args,
...@@ -99,10 +112,7 @@ class Repository(object): ...@@ -99,10 +112,7 @@ class Repository(object):
output, output_err = process.communicate() output, output_err = process.communicate()
retcode = process.poll() retcode = process.poll()
if retcode: if retcode:
message = output_err.strip() raise RepositoryException(retcode, output_err, output)
if not message:
message = output.strip()
raise RepositoryException(message)
return output return output
def execute(self, args): def execute(self, args):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment