Skip to content

Commit 0f70172

Browse files
committed
Clean up bad imports. Give more
explicit error when something fails to be written correctly to a conf file. Otherwise, it is hard to find out which specific object caused the failure.
1 parent a31d484 commit 0f70172

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

contentctl/output/api_json_output.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@
1010
from contentctl.objects.deployment import Deployment
1111

1212
import os
13-
import json
1413
import pathlib
1514

1615
from contentctl.output.json_writer import JsonWriter
17-
from contentctl.objects.enums import SecurityContentType
18-
from contentctl.objects.abstract_security_content_objects.security_content_object_abstract import (
19-
SecurityContentObject_Abstract,
20-
)
2116

2217

2318

contentctl/output/conf_writer.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,20 @@ def writeConfFile(app_output_path:pathlib.Path, template_name : str, config: bui
276276
j2_env = ConfWriter.getJ2Environment()
277277

278278
template = j2_env.get_template(template_name)
279-
try:
280-
for obj in objects:
281-
output = template.render(objects=[obj], app=config.app)
282-
except Exception as e:
283-
print(e)
284-
import code
285-
code.interact(local=locals())
279+
outputs: list[str] = []
280+
for obj in objects:
281+
try:
282+
outputs.append(template.render(objects=[obj], app=config.app))
283+
except Exception as e:
284+
raise Exception(f"Failed writing the following object to file:\n"
285+
f"Name:{obj.name if not isinstance(obj, CustomApp) else obj.title}\n"
286+
f"Type {type(obj)}: \n"
287+
f"Output File: {app_output_path}\n"
288+
f"Error: {str(e)}\n")
286289

287290
output_path.parent.mkdir(parents=True, exist_ok=True)
288291
with open(output_path, 'a') as f:
289-
output = output.encode('utf-8', 'ignore').decode('utf-8')
292+
output = ''.join(outputs).encode('utf-8', 'ignore').decode('utf-8')
290293
f.write(output)
291294
return output_path
292295

0 commit comments

Comments
 (0)