From bf6010f21f0870549921ec0548bfc5e5d220f4d7 Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Wed, 16 Dec 2020 10:19:08 -0500 Subject: [PATCH 1/2] Handle http errors when downloading plugin files. --- .../plugins/pluginmanager/__init__.py | 41 ++++++++++++------- .../plugins/pluginmanager/exceptions.py | 10 +++++ 2 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 src/octoprint/plugins/pluginmanager/exceptions.py diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index d732e0b43..cd03a407d 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -47,6 +47,8 @@ from octoprint.util.version import ( is_python_compatible, ) +from . import exceptions + try: from os import scandir except ImportError: @@ -633,21 +635,32 @@ class PluginManagerPlugin( ) else: - self._logger.error( - "{} is neither an archive nor a python file, can't install that.".format( - source - ) + raise exceptions.InvalidPackageFormat() + except requests.exceptions.HTTPError as e: + self._logger.error("Could not fetch plugin from server, got {}".format(e)) + result = { + "result": False, + "source": source, + "source_type": source_type, + "reason": "Could not fetch plugin from server, got {}".format(e), + } + self._send_result_notification("install", result) + return result + except exceptions.InvalidPackageFormat: + self._logger.error( + "{} is neither an archive nor a python file, can't install that.".format( + source ) - result = { - "result": False, - "source": source, - "source_type": source_type, - "reason": "Could not install plugin from {}, was neither " - "a plugin archive nor a single file plugin".format(source), - } - self._send_result_notification("install", result) - return result - + ) + result = { + "result": False, + "source": source, + "source_type": source_type, + "reason": "Could not install plugin from {}, was neither " + "a plugin archive nor a single file plugin".format(source), + } + self._send_result_notification("install", result) + return result finally: if folder is not None: folder.cleanup() diff --git a/src/octoprint/plugins/pluginmanager/exceptions.py b/src/octoprint/plugins/pluginmanager/exceptions.py new file mode 100644 index 000000000..deddaafbe --- /dev/null +++ b/src/octoprint/plugins/pluginmanager/exceptions.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals + +__author__ = "Gina Häußge " +__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" +__copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License" + + +class InvalidPackageFormat(Exception): + pass From f4a2af750c8210c44252d5586d18d6855e1b7019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 11 Jan 2021 09:24:04 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=8F=20Fix=20file=20header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/plugins/pluginmanager/exceptions.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/octoprint/plugins/pluginmanager/exceptions.py b/src/octoprint/plugins/pluginmanager/exceptions.py index deddaafbe..0b4256018 100644 --- a/src/octoprint/plugins/pluginmanager/exceptions.py +++ b/src/octoprint/plugins/pluginmanager/exceptions.py @@ -1,9 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, division, print_function, unicode_literals -__author__ = "Gina Häußge " __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" -__copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License" +__copyright__ = "Copyright (C) 2020 The OctoPrint Project - Released under terms of the AGPLv3 License" class InvalidPackageFormat(Exception):