mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-14 11:03:10 +00:00
Correctly extract error information if plugin install fails (#5638)
This commit is contained in:
parent
a36ab0c004
commit
39e682cd45
@ -153,13 +153,29 @@ class PluginConfigInstallSerializer(serializers.Serializer):
|
|||||||
success = False
|
success = False
|
||||||
# execute pypi
|
# execute pypi
|
||||||
try:
|
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['result'] = str(result, 'utf-8')
|
||||||
ret['success'] = True
|
ret['success'] = True
|
||||||
|
ret['error'] = False
|
||||||
success = True
|
success = True
|
||||||
except subprocess.CalledProcessError as error: # pragma: no cover
|
except subprocess.CalledProcessError as error: # pragma: no cover
|
||||||
ret['result'] = str(error.output, 'utf-8')
|
output = error.output.decode('utf-8')
|
||||||
ret['error'] = True
|
|
||||||
|
# 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
|
# save plugin to plugin_file if installed successful
|
||||||
if success:
|
if success:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user