Skip to content

Commit

Permalink
feat: handle migration errors from the template
Browse files Browse the repository at this point in the history
fix #2769
  • Loading branch information
lorenzo-cavazzi committed Apr 12, 2022
1 parent 152be29 commit 1eaf8b6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
7 changes: 6 additions & 1 deletion renku/core/template/usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ def update_template(
"break your project"
)

templates_source = fetch_templates_source(source=template_metadata.source, reference=template_metadata.reference)
try:
templates_source = fetch_templates_source(
source=template_metadata.source, reference=template_metadata.reference
)
except errors.InvalidTemplateError:
raise errors.TemplateUpdateError("Template cannot be fetched.")

update_available, latest_reference = templates_source.is_update_available(
id=template_metadata.id, reference=template_metadata.reference, version=template_metadata.version
Expand Down
20 changes: 20 additions & 0 deletions renku/ui/service/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,26 @@ def __init__(self, exception=None):
super().__init__(exception=exception)


class IntermittentProjectTemplateUnavailable(ServiceError):
"""The reference template for the project is currently unavailable.
It may be a temporary issue in accessing the remote template, or it may have been deleted,
moved, or otherwise not-accessible.
"""

code = SVC_ERROR_INTERMITTENT + 140
userMessage = (
"The reference template for the project is currently unavailable."
" It may be a temporary problem, or the template may not be accessible anymore."
)
devMessage = (
"Error accessing the project template. This may be temporary, or the project may not be accessible anymore."
)

def __init__(self, exception=None):
super().__init__(exception=exception)


class IntermittentTimeoutError(ServiceError):
"""An operation timed out."""

Expand Down
9 changes: 7 additions & 2 deletions renku/ui/service/views/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
from renku.ui.service.gateways.gitlab_api_provider import GitlabAPIProvider
from renku.ui.service.views.api_versions import V0_9, V1_0, V1_1, VersionedBlueprint
from renku.ui.service.views.decorators import accepts_json, optional_identity, requires_cache, requires_identity
from renku.ui.service.views.error_handlers import handle_common_except, handle_migration_errors
from renku.ui.service.views.error_handlers import (
handle_common_except,
handle_migration_read_errors,
handle_migration_write_errors,
)
from renku.ui.service.views.v0_9.cache import add_v0_9_specific_endpoints
from renku.ui.service.views.v1_0.cache import add_v1_0_specific_endpoints

Expand Down Expand Up @@ -156,7 +160,7 @@ def list_projects_view(user_data, cache):

@cache_blueprint.route("/cache.migrate", methods=["POST"], provide_automatic_options=False, versions=[V1_1])
@handle_common_except
@handle_migration_errors
@handle_migration_write_errors
@accepts_json
@requires_cache
@requires_identity
Expand Down Expand Up @@ -187,6 +191,7 @@ def migrate_project_view(user_data, cache):
"/cache.migrations_check", methods=["GET"], provide_automatic_options=False, versions=[V1_0, V1_1]
)
@handle_common_except
@handle_migration_read_errors
@requires_cache
@optional_identity
def migration_check_project_view(user_data, cache):
Expand Down
21 changes: 19 additions & 2 deletions renku/ui/service/views/error_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
IntermittentDatasetExistsError,
IntermittentFileNotExistsError,
IntermittentProjectIdError,
IntermittentProjectTemplateUnavailable,
IntermittentRedisError,
IntermittentSettingExistsError,
IntermittentTimeoutError,
Expand Down Expand Up @@ -375,8 +376,24 @@ def decorated_function(*args, **kwargs):
return decorated_function


def handle_migration_errors(f):
"""Wrapper which handles migrations exceptions."""
def handle_migration_read_errors(f):
"""Wrapper which handles migrations read exceptions."""
# noqa
@wraps(f)
def decorated_function(*args, **kwargs):
"""Represents decorated function."""
# NOTE: verify if this may better go in MigrationsCheckCtrl as try/except in to_response()
try:
return f(*args, **kwargs)
except (InvalidTemplateError, TemplateUpdateError, UninitializedProject) as e:
raise IntermittentProjectTemplateUnavailable(e)

return decorated_function


@handle_migration_read_errors
def handle_migration_write_errors(f):
"""Wrapper which handles migrations write exceptions."""
# noqa
@wraps(f)
def decorated_function(*args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions renku/ui/service/views/v1_0/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
from renku.ui.service.serializers.v1_0.cache import ProjectMigrateResponseRPC_1_0
from renku.ui.service.views.api_versions import V0_9, V1_0
from renku.ui.service.views.decorators import accepts_json, requires_cache, requires_identity
from renku.ui.service.views.error_handlers import handle_common_except, handle_migration_errors
from renku.ui.service.views.error_handlers import handle_common_except, handle_migration_write_errors


@handle_common_except
@handle_migration_errors
@handle_migration_write_errors
@accepts_json
@requires_cache
@requires_identity
Expand Down

0 comments on commit 1eaf8b6

Please sign in to comment.