Skip to content

Commit

Permalink
Improve error message representation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejvelichkovski committed Dec 1, 2023
1 parent 8c6e56f commit 0c75209
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
38 changes: 19 additions & 19 deletions backend/test_observer/controllers/promoter/promoter.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ def promote_artefacts(db: Session = Depends(get_db)):
external source
"""
try:
processed_artefacts = promoter_controller(db)
logger.info("INFO: Processed artefacts %s", processed_artefacts)
if False in processed_artefacts.values():
(
processed_artefacts_status,
processed_artefacts_error_messages,
) = promoter_controller(db)
logger.info("INFO: Processed artefacts %s", processed_artefacts_status)
if False in processed_artefacts_status.values():
return JSONResponse(
status_code=500,
content={
"detail": (
"Got some errors while processing the next artefacts: "
", ".join(
[k for k, v in processed_artefacts.items() if v is False]
)
)
artefact_key: processed_artefacts_error_messages[artefact_key]
for artefact_key, artefact_status in processed_artefacts_status.items()
if artefact_status is False
},
)
return JSONResponse(
Expand All @@ -85,32 +85,32 @@ def promote_artefacts(db: Session = Depends(get_db)):
return JSONResponse(status_code=500, content={"detail": str(exc)})


def promoter_controller(session: Session) -> dict:
def promoter_controller(session: Session) -> tuple[dict, dict]:
"""
Orchestrate the snap promoter job
:session: DB connection session
:return: dict with the processed cards and the status of execution
:return: tuple of dicts, the first the processed cards and the status of execution
the second only for the processed cards with the corresponding error message
"""
family_mapping = {
FamilyName.SNAP: run_snap_promoter,
FamilyName.DEB: run_deb_promoter,
}
processed_artefacts_status = {}
processed_artefacts_error_messages = {}
for family_name, promoter_function in family_mapping.items():
artefacts = get_artefacts_by_family(session, family_name, load_stage=True)
processed_artefacts = {}
for artefact in artefacts:
artefact_key = f"{family_name} - {artefact.name} - {artefact.version}"
try:
processed_artefacts[
f"{family_name} - {artefact.name} - {artefact.version}"
] = True
processed_artefacts_status[artefact_key] = True
promoter_function(session, artefact)
except Exception as exc:
processed_artefacts[
f"{family_name} - {artefact.name} - {artefact.version}"
] = False
processed_artefacts_status[artefact_key] = False
processed_artefacts_error_messages[artefact_key] = str(exc)
logger.warning("WARNING: %s", str(exc), exc_info=True)
return processed_artefacts
return processed_artefacts_status, processed_artefacts_error_messages


def run_snap_promoter(session: Session, artefact: Artefact) -> None:
Expand Down
1 change: 1 addition & 0 deletions backend/test_observer/external_apis/snapcraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def get_channel_map_from_snapcraft(arch: str, snapstore: str, snap_name: str):
json_resp = req.json()
if not req.ok:
logger.error(json_resp["error-list"][0]["message"])
req.raise_for_status()

snap_info = SnapInfo(**rename_keys(json_resp))
return snap_info.channel_map

0 comments on commit 0c75209

Please sign in to comment.