Skip to content

Commit 2f1b140

Browse files
committed
fix(management): handle errors in object loading and application deployments instead of throwing exceptions
This will handle the DeisExceptions and derived Exceptions Fixes #761 Fixes #741
1 parent a43f135 commit 2f1b140

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

rootfs/api/management/commands/load_db_state_to_k8s.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.shortcuts import get_object_or_404
33

44
from api.models import Key, App, Domain, Certificate, Config
5+
from api.exceptions import DeisException
56

67

78
class Command(BaseCommand):
@@ -13,7 +14,11 @@ def handle(self, *args, **options):
1314
print("Publishing DB state to kubernetes...")
1415
for model in (Key, App, Domain, Certificate, Config):
1516
for obj in model.objects.all():
16-
obj.save()
17+
try:
18+
obj.save()
19+
except DeisException as error:
20+
print('ERROR: Problem saving to model {} for {}'
21+
'due to {}'.format(str(model.__name__), str(obj), str(error)))
1722

1823
# certificates have to be attached to domains to create k8s secrets
1924
for cert in Certificate.objects.all():
@@ -29,6 +34,11 @@ def handle(self, *args, **options):
2934
print('WARNING: {} has no build associated with '
3035
'its latest release. Skipping deployment...'.format(application))
3136
continue
32-
application.deploy(rel)
37+
38+
try:
39+
application.deploy(rel)
40+
except DeisException as error:
41+
print('ERROR: There was a problem deploying {} '
42+
'due to {}'.format(application, str(error)))
3343

3444
print("Done Publishing DB state to kubernetes.")

rootfs/api/models/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ def set_tags(self, previous_config):
102102
if old_tags:
103103
old = ['{}={}'.format(key, value) for key, value in old_tags.items()]
104104
new = set(labels) - set(old)
105-
message += ' - Addition of {} is the cause'.format(', '.join(new))
105+
if new:
106+
message += ' - Addition of {} is the cause'.format(', '.join(new))
106107

107108
raise DeisException(message)
108109

0 commit comments

Comments
 (0)