From 39e682cd45cb48c14a307954b1b0d3beffe71716 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 1 Oct 2023 14:29:08 +1100 Subject: [PATCH] Correctly extract error information if plugin install fails (#5638) --- InvenTree/plugin/serializers.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/InvenTree/plugin/serializers.py b/InvenTree/plugin/serializers.py index 34ecd7fa66..826dec6ed0 100644 --- a/InvenTree/plugin/serializers.py +++ b/InvenTree/plugin/serializers.py @@ -153,13 +153,29 @@ class PluginConfigInstallSerializer(serializers.Serializer): success = False # execute pypi try: - result = subprocess.check_output(command, cwd=settings.BASE_DIR.parent) + result = subprocess.check_output(command, cwd=settings.BASE_DIR.parent, stderr=subprocess.STDOUT) ret['result'] = str(result, 'utf-8') ret['success'] = True + ret['error'] = False success = True except subprocess.CalledProcessError as error: # pragma: no cover - ret['result'] = str(error.output, 'utf-8') - ret['error'] = True + output = error.output.decode('utf-8') + + # Raise a ValidationError as the plugin install failed + errors = [] + + for msg in output.split('\n'): + msg = msg.strip() + if msg: + errors.append(msg) + + if len(errors) == 0: + errors.append(_('Unknown error')) + + if len(errors) > 1: + raise ValidationError(errors) + else: + raise ValidationError(errors[0]) # save plugin to plugin_file if installed successful if success: