Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Better error messages in ideascale importer | NPG-7753 #484

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading