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
feat: handle migration errors from the template #2819
Changes from 6 commits
1eaf8b6
87a3562
c50d961
7793801
8a62e49
daed69f
3a23991
d409553
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,7 +132,15 @@ 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.TemplateMissingReferenceError as e: | ||
message = f"{str(e)}; You can still manually update the template and set a difference reference." | ||
raise errors.TemplateUpdateError(message) | ||
except errors.InvalidTemplateError: | ||
raise errors.TemplateUpdateError("Template cannot be fetched.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason to convert these errors to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea was to simplify catching/handling them in the service and in the CLI. For the latter, throwing a new error results in a clean error message, while not doing it means a long and confusing stack trace is printed (see screen below). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. It's fine to do it here. |
||
|
||
update_available, latest_reference = templates_source.is_update_available( | ||
id=template_metadata.id, reference=template_metadata.reference, version=template_metadata.version | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
MigrationRequired, | ||
ParameterError, | ||
RenkuException, | ||
TemplateMissingReferenceError, | ||
TemplateUpdateError, | ||
UninitializedProject, | ||
) | ||
|
@@ -44,6 +45,7 @@ | |
IntermittentDatasetExistsError, | ||
IntermittentFileNotExistsError, | ||
IntermittentProjectIdError, | ||
IntermittentProjectTemplateUnavailable, | ||
IntermittentRedisError, | ||
IntermittentSettingExistsError, | ||
IntermittentTimeoutError, | ||
|
@@ -65,6 +67,7 @@ | |
UserNonRenkuProjectError, | ||
UserOutdatedProjectError, | ||
UserProjectCreationError, | ||
UserProjectTemplateReferenceError, | ||
UserRepoBranchInvalidError, | ||
UserRepoNoAccessError, | ||
UserRepoUrlInvalidError, | ||
|
@@ -375,8 +378,26 @@ 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get this comment. Is it a left-over TODO? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ouch! Yes, that is a leftover, thanks for spotting it! |
||
try: | ||
return f(*args, **kwargs) | ||
except TemplateMissingReferenceError as e: | ||
raise UserProjectTemplateReferenceError(e) | ||
except (InvalidTemplateError, TemplateUpdateError) as e: | ||
raise IntermittentProjectTemplateUnavailable(e) | ||
|
||
return decorated_function | ||
|
||
|
||
@handle_migration_read_errors | ||
def handle_migration_write_errors(f): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to distinguish between migration read/write errors. AFAIK, the difference is that in read we only check for migration; so, the same errors can happen in both cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The write section handles a couple of extra errors, and those throw a more severe error ( |
||
"""Wrapper which handles migrations write exceptions.""" | ||
# noqa | ||
@wraps(f) | ||
def decorated_function(*args, **kwargs): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reference {reference} -> reference '{reference}'
so that it's more visible what the reference is.