catch unicodedecodeerror

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-10-15 01:11:54 +02:00
parent c64ab97f2a
commit ad1e51cb2e

View file

@ -40,6 +40,13 @@ class RemoteScriptError(cdist.Error):
def __str__(self): def __str__(self):
return "Remote script execution failed: %s %s" % (self.script, self.command) return "Remote script execution failed: %s %s" % (self.script, self.command)
class DecodeError(cdist.Error):
def __init__(self, command):
self.command = command
def __str__(self):
return "Cannot decode output of " + " ".join(self.command)
class Remote(object): class Remote(object):
"""Execute commands remotely. """Execute commands remotely.
@ -121,6 +128,8 @@ class Remote(object):
raise cdist.Error("Command failed: " + " ".join(command)) raise cdist.Error("Command failed: " + " ".join(command))
except OSError as error: except OSError as error:
raise cdist.Error(" ".join(*args) + ": " + error.args[1]) raise cdist.Error(" ".join(*args) + ": " + error.args[1])
except UnicodeDecodeError:
raise DecodeError(command)
def run_script(self, script, env=None, return_output=False): def run_script(self, script, env=None, return_output=False):
"""Run the given script with the given environment on the remote side. """Run the given script with the given environment on the remote side.