From 621d9917888133030c5a13a13731a3fc4b7f6d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 23 Mar 2016 13:07:04 +0100 Subject: [PATCH] Better error reporting in update script & CLI --- src/octoprint/plugins/softwareupdate/cli.py | 2 +- .../softwareupdate/scripts/update-octoprint.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/octoprint/plugins/softwareupdate/cli.py b/src/octoprint/plugins/softwareupdate/cli.py index e0554aac..e1e45569 100644 --- a/src/octoprint/plugins/softwareupdate/cli.py +++ b/src/octoprint/plugins/softwareupdate/cli.py @@ -96,7 +96,7 @@ def commands(cli_group, pass_octoprint_ctx, *args, **kwargs): click.echo("Updating {} to {}...".format(plugin_message_data["name"], plugin_message_data["target"])) elif plugin_message_type == "update_failed": - click.echo("\t... failed: {}".format(plugin_message_data["reason"])) + click.echo("\t... failed :(") elif plugin_message_type == "loglines" and "loglines" in plugin_message_data: for entry in plugin_message_data["loglines"]: diff --git a/src/octoprint/plugins/softwareupdate/scripts/update-octoprint.py b/src/octoprint/plugins/softwareupdate/scripts/update-octoprint.py index 1733a86c..1ed5b0c7 100644 --- a/src/octoprint/plugins/softwareupdate/scripts/update-octoprint.py +++ b/src/octoprint/plugins/softwareupdate/scripts/update-octoprint.py @@ -130,11 +130,15 @@ def _python(args, cwd, python_executable, sudo=False): return None, None +def _to_error(*lines): + return u"".join(map(lambda x: _to_unicode(x, errors="replace"), lines)) + + def update_source(git_executable, folder, target, force=False): print(">>> Running: git diff --shortstat") returncode, stdout, stderr = _git(["diff", "--shortstat"], folder, git_executable=git_executable) if returncode != 0: - raise RuntimeError("Could not update, \"git diff\" failed with returncode %d: %s" % (returncode, stdout)) + raise RuntimeError("Could not update, \"git diff\" failed with returncode %d: %s" % (returncode, _to_error(*stdout))) if stdout and "".join(stdout).strip(): # we got changes in the working tree, maybe from the user, so we'll now rescue those into a patch import time @@ -154,17 +158,17 @@ def update_source(git_executable, folder, target, force=False): print(">>> Running: git reset --hard") returncode, stdout, stderr = _git(["reset", "--hard"], folder, git_executable=git_executable) if returncode != 0: - raise RuntimeError("Could not update, \"git reset --hard\" failed with returncode %d: %s" % (returncode, stdout)) + raise RuntimeError("Could not update, \"git reset --hard\" failed with returncode %d: %s" % (returncode, _to_error(*stdout))) print(">>> Running: git clean -f -d -e *-preupdate.patch") returncode, stdout, stderr = _git(["clean", "-f", "-d", "-e", "*-preupdate.patch"], folder, git_executable=git_executable) if returncode != 0: - raise RuntimeError("Could not update, \"git clean -f\" failed with returcode %d: %s" % (returncode, stdout)) + raise RuntimeError("Could not update, \"git clean -f\" failed with returcode %d: %s" % (returncode, _to_error(*stdout))) print(">>> Running: git pull") returncode, stdout, stderr = _git(["pull"], folder, git_executable=git_executable) if returncode != 0: - raise RuntimeError("Could not update, \"git pull\" failed with returncode %d: %s" % (returncode, stdout)) + raise RuntimeError("Could not update, \"git pull\" failed with returncode %d: %s" % (returncode, _to_error(*stdout))) if force: reset_command = ["reset", "--hard"] @@ -173,7 +177,7 @@ def update_source(git_executable, folder, target, force=False): print(">>> Running: git %s" % " ".join(reset_command)) returncode, stdout, stderr = _git(reset_command, folder, git_executable=git_executable) if returncode != 0: - raise RuntimeError("Error while updating, \"git %s\" failed with returncode %d: %s" % (" ".join(reset_command), returncode, stdout)) + raise RuntimeError("Error while updating, \"git %s\" failed with returncode %d: %s" % (" ".join(reset_command), returncode, _to_error(*stdout))) def install_source(python_executable, folder, user=False, sudo=False): @@ -189,7 +193,7 @@ def install_source(python_executable, folder, user=False, sudo=False): args.append("--user") returncode, stdout, stderr = _python(args, folder, python_executable, sudo=sudo) if returncode != 0: - raise RuntimeError("Could not update, \"python setup.py install\" failed with returncode %d: %s" % (returncode, stdout)) + raise RuntimeError("Could not update, \"python setup.py install\" failed with returncode %d: %s" % (returncode, _to_error(*stdout))) def parse_arguments():