diff --git a/utilities/ideascale-importer/ideascale_importer/cli/ideascale.py b/utilities/ideascale-importer/ideascale_importer/cli/ideascale.py index 7ca4c8b14b..4a1641ac82 100644 --- a/utilities/ideascale-importer/ideascale_importer/cli/ideascale.py +++ b/utilities/ideascale-importer/ideascale_importer/cli/ideascale.py @@ -71,8 +71,11 @@ async def inner( ideascale_api_url, ) - await importer.connect() - await importer.run() - await importer.close() + try: + await importer.connect() + await importer.run() + await importer.close() + except Exception as e: + logger.error(e) asyncio.run(inner(event_id, campaign_group_id, stage_ids, proposals_scores_csv, ideascale_api_url)) diff --git a/utilities/ideascale-importer/ideascale_importer/ideascale/importer.py b/utilities/ideascale-importer/ideascale_importer/ideascale/importer.py index ec31eeba9d..69d147a527 100644 --- a/utilities/ideascale-importer/ideascale_importer/ideascale/importer.py +++ b/utilities/ideascale-importer/ideascale_importer/ideascale/importer.py @@ -60,13 +60,22 @@ def from_json_file(path: str) -> "Config": class ReadConfigException(Exception): """Raised when the configuration file cannot be read.""" - ... + def __init__(self, cause: str): + super().__init__(f"Failed to read config file: {cause}") class ReadProposalsScoresCsv(Exception): """Raised when the proposals impact scores csv cannot be read.""" - ... + def __init__(self, cause: str): + super().__init__(f"Failed to read proposals impact score file: {cause}") + + +class MapObjectiveError(Exception): + """Raised when mapping an objective from campaign data fails.""" + + def __init__(self, objective_field: str, campaign_field: str, cause: str): + super().__init__(f"Failed to map objective '{objective_field}' from campaign '{campaign_field}': {cause}") class Mapper: @@ -79,7 +88,10 @@ def __init__(self, vote_options_id: int, config: Config): def map_objective(self, a: Campaign, event_id: int) -> ideascale_importer.db.models.Challenge: """Map a IdeaScale campaign into a objective.""" - reward = parse_reward(a.tagline) + try: + reward = parse_reward(a.tagline) + except InvalidRewardsString as e: + raise MapObjectiveError("reward", "tagline", str(e)) return ideascale_importer.db.models.Challenge( row_id=0, @@ -169,7 +181,8 @@ class Reward: class InvalidRewardsString(Exception): """Raised when the reward string cannot be parsed.""" - ... + def __init__(self): + super().__init__("Invalid rewards string") def parse_reward(s: str) -> Reward: