Skip to content

Commit 3f6b13d

Browse files
committed
WIP: update error handling for notifications
1 parent 49eb605 commit 3f6b13d

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

invenio_rdm_records/notifications/builders.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,11 @@ def build(
666666
generic_repository: GenericRepository,
667667
generic_release: GenericRelease,
668668
draft,
669+
error_message: str,
669670
):
670671
notification = super().build(provider, generic_repository, generic_release)
671672
notification.context["draft"] = EntityResolverRegistry.reference_entity(draft)
673+
notification.context["error_message"] = error_message
672674
return notification
673675

674676
context = [EntityResolve(key="draft")]

invenio_rdm_records/services/vcs/metadata.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import yaml
1313
from flask import current_app
1414
from invenio_i18n import _
15-
from invenio_vcs.errors import CustomVCSMetadataError
15+
from invenio_vcs.errors import CustomVCSReleaseNoRetryError
1616
from invenio_vcs.generic_models import GenericContributor
1717
from marshmallow import Schema, ValidationError
1818
from mistune import markdown
@@ -145,8 +145,9 @@ def citation_metadata(self):
145145
# Load metadata from citation file and serialize it
146146
return self.load_citation_metadata(data)
147147
except ValidationError as e:
148-
# Wrap the error into CustomVCSMetadataError() so it can be handled upstream
149-
raise CustomVCSMetadataError(file=citation_file_path, message=e.messages)
148+
# Wrap the error into CustomVCSReleaseNoRetryError() so it can be handled upstream.
149+
# This also ensures the release isn't retried without user action.
150+
raise CustomVCSReleaseNoRetryError(message=e.messages)
150151

151152
@property
152153
def extra_metadata(self):

invenio_rdm_records/services/vcs/release.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from invenio_i18n import lazy_gettext as _
1515
from invenio_notifications.services.uow import NotificationOp
1616
from invenio_records_resources.services.uow import UnitOfWork
17+
from invenio_vcs.errors import CustomVCSReleaseNoRetryError
1718
from invenio_vcs.models import ReleaseStatus
1819
from invenio_vcs.service import VCSRelease
1920

@@ -237,6 +238,20 @@ def publish(self):
237238
# Flag release as FAILED and raise the exception
238239
self.release_failed()
239240

241+
# The release publish can fail for a wide range of reasons, each of which have various inconsistent error types.
242+
# Some errors have a 'message' attribute or a 'description' attribute, which is not the value that gets used
243+
# when the error is stringified.
244+
# Some errors might not have any accessible message, so we use the class name as a last resort.
245+
error_message = str(ex)
246+
if not error_message:
247+
if hasattr(ex, "message"):
248+
# Need to stringify the LazyString, otherwise serialisation will fail
249+
error_message = str(ex.message)
250+
elif hasattr(ex, "description"):
251+
error_message = str(ex.description)
252+
else:
253+
error_message = type(ex).__name__
254+
240255
with UnitOfWork(db.session) as uow:
241256
uow.register(
242257
NotificationOp(
@@ -245,6 +260,7 @@ def publish(self):
245260
generic_repository=self.generic_repo,
246261
generic_release=self.generic_release,
247262
draft=draft,
263+
error_message=error_message,
248264
)
249265
)
250266
)
@@ -253,7 +269,8 @@ def publish(self):
253269
# Commit the FAILED state, other changes were already rollbacked by the UOW
254270
db.session.commit()
255271

256-
raise ex
272+
# Wrap the error to ensure Celery does not attempt to retry it (since user action is needed to resolve the problem)
273+
raise CustomVCSReleaseNoRetryError(message=error_message)
257274

258275
def process_release(self):
259276
"""Processes a github release.

invenio_rdm_records/templates/semantic-ui/invenio_notifications/repository-release.failure.jinja

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
{% set repository_full_name = notification.context.repository_full_name %}
22
{% set release_tag = notification.context.release_tag %}
33
{% set draft = notification.context.draft %}
4+
{% set error_message = notification.context.error_message %}
45

56
{% set account_settings_link = invenio_url_for("invenio_notifications_settings.index") %}
67
{% set draft_link = draft["links"]["self_html"] %}
78

89
{%- block subject -%}
9-
{{ _("There was a problem publishing a release from {repository_name}", repository_name=repository_full_name) }}
10+
{{ _("There was a problem publishing a release from %(repository_name)s", repository_name=repository_full_name) }}
1011
{%- endblock subject -%}
1112

1213
{%- block html_body -%}
1314
<table style="font-family:'Lato',Helvetica,Arial,sans-serif;border-spacing:15px">
1415
<tr>
15-
<td>{{ _("Release {release_tag} of {repository_name} failed to publish.", release_tag=release_tag, repository_name=repository_full_name )}}
16+
<td>{{ _("Release %(release_tag)s of %(repository_name)s failed to publish.", release_tag=release_tag, repository_name=repository_full_name )}}
1617
</td>
1718
</tr>
19+
<tr>
20+
<td>{{ _("Reason:") }} <strong>{{ error_message }}</strong></td>
21+
</tr>
1822
<tr>
1923
<td>{{ _("For more details and to fix any errors,") }} <a href="{{ draft_link }}" class="button">{{ _("view the unpublished draft record.") }}</a></td>
2024
</tr>
@@ -28,7 +32,9 @@
2832
{%- endblock html_body -%}
2933

3034
{%- block plain_body -%}
31-
{{ _("Release {release_tag} of {repository_name} failed to publish.", release_tag=release_tag, repository_name=repository_full_name) }}
35+
{{ _("Release %(release_tag)s of %(repository_name)s failed to publish.", release_tag=release_tag, repository_name=repository_full_name) }}
36+
37+
{{ _("Reason:") }} {{error_message}}
3238

3339
{{ _("For more details and to fix any errors,") }} [{{ _("view the unpublished draft record.") }}]({{ draft_link }})
3440

@@ -37,7 +43,9 @@
3743

3844
{# Markdown for Slack/Mattermost/chat #}
3945
{%- block md_body -%}
40-
{{ _("Release {release_tag} of {repository_name} failed to publish.", release_tag=release_tag, repository_name=repository_full_name )}}
46+
{{ _("Release %(release_tag)s of %(repository_name)s failed to publish.", release_tag=release_tag, repository_name=repository_full_name )}}
47+
48+
{{ _("Reason:") }} {{error_message}}
4149

4250
{{ _("For more details and to fix any errors,") }} [{{ _("view the unpublished draft record.") }}]({{ draft_link }})
4351

invenio_rdm_records/templates/semantic-ui/invenio_notifications/repository-release.success.jinja

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
{% set record_link = record.data["links"]["self_html"] %}
77

88
{%- block subject -%}
9-
{{ _("A release from {repository_name} was published successfully", repository_name=repository_full_name) }}
9+
{{ _("A release from %(repository_name)s was published successfully", repository_name=repository_full_name) }}
1010
{%- endblock subject -%}
1111

1212
{%- block html_body -%}
1313
<table style="font-family:'Lato',Helvetica,Arial,sans-serif;border-spacing:15px">
1414
<tr>
15-
<td>{{ _("Release {release_tag} of {repository_name} has been received and published successfully.", release_tag=release_tag, repository_name=repository_full_name) }}
15+
<td>{{ _("Release %(release_tag)s of %(repository_name)s has been received and published successfully.", release_tag=release_tag, repository_name=repository_full_name) }}
1616
</td>
1717
</tr>
1818
<tr>
@@ -28,7 +28,7 @@
2828
{%- endblock html_body -%}
2929

3030
{%- block plain_body -%}
31-
{{ _("Release {release_tag} of {repository_name} has been received and published successfully.", release_tag=release_tag, repository_name=repository_full_name) }}
31+
{{ _("Release %(release_tag)s of %(repository_name)s has been received and published successfully.", release_tag=release_tag, repository_name=repository_full_name) }}
3232

3333
{{ _("For more details,") }} [{{ _("view the published record.") }}]({{ record_link }})
3434

@@ -37,7 +37,7 @@
3737

3838
{# Markdown for Slack/Mattermost/chat #}
3939
{%- block md_body -%}
40-
{{ _("Release {release_tag} of {repository_name} has been received and published successfully.", release_tag=release_tag, repository_name=repository_full_name) }}
40+
{{ _("Release %(release_tag)s of %(repository_name)s has been received and published successfully.", release_tag=release_tag, repository_name=repository_full_name) }}
4141

4242
{{ _("For more details,") }} [{{ _("view the published record.") }}]({{ record_link }})
4343

0 commit comments

Comments
 (0)