Skip to content

Commit

Permalink
Correctly extract error information if plugin install fails (#5638)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Oct 1, 2023
1 parent a36ab0c commit 39e682c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions InvenTree/plugin/serializers.py
Expand Up @@ -153,13 +153,29 @@ def save(self):
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:
Expand Down

0 comments on commit 39e682c

Please sign in to comment.