Skip to content

Commit

Permalink
chore: Better error messages in ideascale importer
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeRosa committed Jul 25, 2023
1 parent 866eceb commit 0e465fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0e465fc

Please sign in to comment.