Skip to content
Snippets Groups Projects
Commit 39f4d803 authored by Sjoerd Simons's avatar Sjoerd Simons
Browse files

Raise an exception if an ssh command fails


ade install failed for me as my target device doesn't have
ribchester-bundle, however it did so without giving any indication
something was wrong at all.

Sort this out by raising an exception if the remote command returns a
non-zero exit status.

Signed-off-by: default avatarSjoerd Simons <sjoerd.simons@collabora.co.uk>

Differential Revision: https://phabricator.apertis.org/D5260
parent fcdbf1da
No related branches found
No related tags found
No related merge requests found
......@@ -105,6 +105,19 @@ class NotSupportedError(Exception):
def __init__(self):
pass
class CommandFailedError(Exception):
def __init__(self, stdout, stderr, exit_status):
self.stdout = stdout
self.stderr = stderr
self.exit_status = exit_status
def __str__(self):
return """Exit code: {}
Stdout: {}
Stderr: {}""".format(self.exit_status,
self.stdout,
self.stderr)
def is_valid_url(url):
result = urlparse(url)
......@@ -221,7 +234,13 @@ class Device:
def _exec(self, *args):
with closing(self._connect()) as ssh:
stdin, stdout, stderr = ssh.exec_command(' '.join(args))
return stdout.read().decode().strip()
out = stdout.read().decode().strip()
err = stderr.read().decode().strip()
status = stdout.channel.recv_exit_status ()
if status != 0:
raise CommandFailedError(out, err, status)
return out
def load_sysroot_version(self):
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment