Skip to content

Commit

Permalink
fix(service): fix error message for invalid templates (#3349)
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Mar 14, 2023
1 parent 3b4fa36 commit 6798b1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions renku/ui/service/controllers/templates_create_project.py
Expand Up @@ -29,7 +29,7 @@
from renku.ui.service.config import MESSAGE_PREFIX
from renku.ui.service.controllers.api.abstract import ServiceCtrl
from renku.ui.service.controllers.api.mixins import RenkuOperationMixin
from renku.ui.service.errors import UserProjectCreationError
from renku.ui.service.errors import UserProjectCreationError, UserTemplateInvalidError
from renku.ui.service.serializers.templates import ProjectTemplateRequest, ProjectTemplateResponseRPC
from renku.ui.service.utils import new_repo_push
from renku.ui.service.views import result_response
Expand Down Expand Up @@ -116,10 +116,12 @@ def setup_template(self):
identifier = self.ctx["identifier"]
try:
self.template = templates_source.get_template(id=identifier, reference=None)
except (errors.InvalidTemplateError, errors.TemplateNotFoundError) as e:
except errors.TemplateNotFoundError as e:
raise UserProjectCreationError(
error_message=f"the template '{identifier}' does not exist in the target template's repository"
) from e
except errors.InvalidTemplateError as e:
raise UserTemplateInvalidError(error_message=f"the template '{identifier}' is invalid") from e

repository = Repository(templates_source.path)
self.template_version = repository.head.commit.hexsha
Expand Down
12 changes: 8 additions & 4 deletions renku/ui/service/errors.py
Expand Up @@ -261,11 +261,15 @@ class UserTemplateInvalidError(ServiceError):
"""The provided URL doesn't lead to a valid template repository."""

code = SVC_ERROR_USER + 101
userMessage = "The target repository is not a valid Renku template repository."
devMessage = "Target repository is not a valid template."
userMessage = "The target repository is not a valid Renku template repository: {error_message}"
devMessage = "Target repository is not a valid template.: {error_message}"

def __init__(self, exception=None):
super().__init__(exception=exception)
def __init__(self, exception=None, error_message=ERROR_NOT_AVAILABLE):
super().__init__(
userMessage=self.userMessage.format(error_message=error_message),
devMessage=self.devMessage.format(error_message=error_message),
exception=exception,
)


class UserProjectCreationError(ServiceError):
Expand Down

0 comments on commit 6798b1a

Please sign in to comment.