-
Notifications
You must be signed in to change notification settings - Fork 84
Add more Pulp Exceptions. #1186
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add more Pulp Exceptions. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| from gettext import gettext as _ | ||
|
|
||
| from pulpcore.plugin.exceptions import PulpException | ||
|
|
||
|
|
||
| class ProvenanceVerificationError(PulpException): | ||
| """ | ||
| Raised when provenance verification fails. | ||
| """ | ||
|
|
||
| error_code = "PLPY0001" | ||
|
Contributor
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. Do we already have a naming convention for plugins? Pulpcore uses "PLP", this introduces "PLPY"
Author
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. We don't have a strict convention for plugins, but some plugins have already created exceptions with codes, so until we have a reason to make it all stricter we will go with it. |
||
|
|
||
| def __init__(self, message): | ||
| """ | ||
| :param message: Description of the provenance verification error | ||
| :type message: str | ||
| """ | ||
| self.message = message | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _("Provenance verification failed: {message}").format( | ||
| message=self.message | ||
| ) | ||
|
|
||
|
|
||
| class AttestationVerificationError(PulpException): | ||
| """ | ||
| Raised when attestation verification fails. | ||
| """ | ||
|
|
||
| error_code = "PLPY0002" | ||
|
|
||
| def __init__(self, message): | ||
| """ | ||
| :param message: Description of the attestation verification error | ||
| :type message: str | ||
| """ | ||
| self.message = message | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _("Attestation verification failed: {message}").format( | ||
| message=self.message | ||
| ) | ||
|
|
||
|
|
||
| class PackageSubstitutionError(PulpException): | ||
| """ | ||
| Raised when packages with the same filename but different checksums are being added. | ||
| """ | ||
|
|
||
| error_code = "PLPY0003" | ||
|
|
||
| def __init__(self, duplicates): | ||
| """ | ||
| :param duplicates: Description of duplicate packages | ||
| :type duplicates: str | ||
| """ | ||
| self.duplicates = duplicates | ||
|
|
||
| def __str__(self): | ||
| return ( | ||
| f"[{self.error_code}] " | ||
| + _( | ||
| "Found duplicate packages being added with the same filename but different checksums. " # noqa: E501 | ||
| ) | ||
| + _("To allow this, set 'allow_package_substitution' to True on the repository. ") | ||
| + _("Conflicting packages: {duplicates}").format(duplicates=self.duplicates) | ||
| ) | ||
|
Comment on lines
+61
to
+68
Contributor
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. |
||
|
|
||
|
|
||
| class UnsupportedProtocolError(PulpException): | ||
| """ | ||
| Raised when an unsupported protocol is used for syncing. | ||
| """ | ||
|
|
||
| error_code = "PLPY0004" | ||
|
|
||
| def __init__(self, protocol): | ||
| """ | ||
| :param protocol: The unsupported protocol | ||
| :type protocol: str | ||
| """ | ||
| self.protocol = protocol | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _( | ||
| "Only HTTP(S) is supported for python syncing, got: {protocol}" | ||
| ).format(protocol=self.protocol) | ||
|
|
||
|
|
||
| class MissingRelativePathError(PulpException): | ||
| """ | ||
| Raised when relative_path field is missing during package upload. | ||
| """ | ||
|
|
||
| error_code = "PLPY0005" | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _("This field is required: relative_path") | ||
|
|
||
|
|
||
| class InvalidPythonExtensionError(PulpException): | ||
| """ | ||
| Raised when a file has an invalid Python package extension. | ||
| """ | ||
|
|
||
| error_code = "PLPY0006" | ||
|
|
||
| def __init__(self, filename): | ||
| """ | ||
| :param filename: The filename with invalid extension | ||
| :type filename: str | ||
| """ | ||
| self.filename = filename | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _( | ||
| "Extension on {filename} is not a valid python extension " | ||
| "(.whl, .exe, .egg, .tar.gz, .tar.bz2, .zip)" | ||
| ).format(filename=self.filename) | ||
|
|
||
|
|
||
| class InvalidProvenanceError(PulpException): | ||
| """ | ||
| Raised when uploaded provenance data is invalid. | ||
| """ | ||
|
|
||
| error_code = "PLPY0007" | ||
|
|
||
| def __init__(self, message): | ||
| """ | ||
| :param message: Description of the provenance validation error | ||
| :type message: str | ||
| """ | ||
| self.message = message | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _( | ||
| "The uploaded provenance is not valid: {message}" | ||
| ).format(message=self.message) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,9 @@ | |
|
|
||
| from aiohttp import ClientResponseError, ClientError | ||
| from lxml.etree import LxmlError | ||
| from gettext import gettext as _ | ||
| from functools import partial | ||
|
|
||
| from rest_framework import serializers | ||
|
|
||
| from pulpcore.plugin.exceptions import SyncError | ||
| from pulpcore.plugin.download import HttpDownloader | ||
| from pulpcore.plugin.models import Artifact, ProgressReport, Remote, Repository | ||
| from pulpcore.plugin.stages import ( | ||
|
|
@@ -17,6 +15,7 @@ | |
| Stage, | ||
| ) | ||
|
|
||
| from pulp_python.app.exceptions import UnsupportedProtocolError | ||
|
Contributor
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 this? I do not remember that is was reported by CI. It also looks like sth that should be in pulpcore. |
||
| from pulp_python.app.models import ( | ||
| PythonPackageContent, | ||
| PythonRemote, | ||
|
|
@@ -54,7 +53,7 @@ def sync(remote_pk, repository_pk, mirror): | |
| repository = Repository.objects.get(pk=repository_pk) | ||
|
|
||
| if not remote.url: | ||
| raise serializers.ValidationError(detail=_("A remote must have a url attribute to sync.")) | ||
| raise SyncError("A remote must have a url attribute to sync.") | ||
|
|
||
| first_stage = PythonBanderStage(remote) | ||
| DeclarativeVersion(first_stage, repository, mirror).create() | ||
|
|
@@ -117,7 +116,8 @@ async def run(self): | |
| url = self.remote.url.rstrip("/") | ||
| downloader = self.remote.get_downloader(url=url) | ||
| if not isinstance(downloader, HttpDownloader): | ||
| raise ValueError("Only HTTP(S) is supported for python syncing") | ||
| protocol = type(downloader).__name__ | ||
| raise UnsupportedProtocolError(protocol) | ||
|
|
||
| async with Master(url, allow_non_https=True) as master: | ||
| # Replace the session with the remote's downloader session | ||
|
|
||
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.
This is not a bug, but rather a feature.