-
Notifications
You must be signed in to change notification settings - Fork 87
Add more Pulp Exceptions. #1440
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
Open
aKlimau
wants to merge
1
commit into
pulp:main
Choose a base branch
from
aKlimau:add-pulp-exceptions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add more Pulp Exceptions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| from gettext import gettext as _ | ||
|
|
||
| from pulpcore.plugin.exceptions import PulpException | ||
|
|
||
|
|
||
| class NoReleaseFile(PulpException): | ||
| """ | ||
| Raised when no Release file can be found at the expected URL. | ||
| """ | ||
|
|
||
| error_code = "DEB0001" | ||
|
|
||
| def __init__(self, url): | ||
| super().__init__() | ||
| self.url = url | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _( | ||
| "Could not find a Release file at '{url}', try checking the 'url' and " | ||
| "'distributions' option on your remote" | ||
| ).format(url=self.url) | ||
|
|
||
|
|
||
| class NoValidSignatureForKey(PulpException): | ||
| """ | ||
| Raised when verification of a Release file with the provided GPG key fails. | ||
| """ | ||
|
|
||
| error_code = "DEB0002" | ||
|
|
||
| def __init__(self, url): | ||
| super().__init__() | ||
| self.url = url | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _( | ||
| "Unable to verify any Release files from '{url}' using the GPG key provided." | ||
| ).format(url=self.url) | ||
|
|
||
|
|
||
| class NoPackageIndexFile(PulpException): | ||
| """ | ||
| Raised when no suitable package index file can be found. | ||
| """ | ||
|
|
||
| error_code = "DEB0003" | ||
|
|
||
| def __init__(self, relative_dir): | ||
| super().__init__() | ||
| self.relative_dir = relative_dir | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _( | ||
| "No suitable package index files found in '{relative_dir}'. If you are syncing from " | ||
| "a partial mirror, you can ignore this error for individual remotes " | ||
| "(ignore_missing_package_indices='True') or system wide " | ||
| "(FORCE_IGNORE_MISSING_PACKAGE_INDICES setting)." | ||
| ).format(relative_dir=self.relative_dir) | ||
|
|
||
|
|
||
| class MissingReleaseFileField(PulpException): | ||
| """ | ||
| Raised when an upstream Release file is missing a required field. | ||
| """ | ||
|
|
||
| error_code = "DEB0004" | ||
|
|
||
| def __init__(self, distribution, field): | ||
| super().__init__() | ||
| self.distribution = distribution | ||
| self.field = field | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _( | ||
| "The release file for distribution '{distribution}' is missing " | ||
| "the required field '{field}'." | ||
| ).format(distribution=self.distribution, field=self.field) | ||
|
|
||
|
|
||
| class UnknownNoSupportForArchitectureAllValue(PulpException): | ||
| """ | ||
| Exception Signifying that the Release file contains the 'No-Support-for-Architecture-all' field, | ||
| but with a value other than 'Packages'. We interpret this as an error since this would likely | ||
| signify some unknown repo format, that pulp_deb is more likely to get wrong than right! | ||
| """ | ||
|
|
||
| error_code = "DEB0005" | ||
|
|
||
| def __init__(self, release_file_path, unknown_value): | ||
| super().__init__() | ||
| self.release_file_path = release_file_path | ||
| self.unknown_value = unknown_value | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _( | ||
| "The Release file at '{release_file_path}' contains the " | ||
| "'No-Support-for-Architecture-all' field, with unknown value '{unknown_value}'! " | ||
| "pulp_deb currently only understands the value 'Packages' for this field, please " | ||
| "open an issue at https://github.com/pulp/pulp_deb/issues specifying the remote " | ||
| "you are attempting to sync, so that we can improve pulp_deb!" | ||
| ).format( | ||
| release_file_path=self.release_file_path, | ||
| unknown_value=self.unknown_value, | ||
| ) | ||
|
|
||
|
|
||
| class DuplicateReleaseFile(PulpException): | ||
| """ | ||
| Raised when multiple ReleaseFile objects exist where only one is expected. | ||
| """ | ||
|
|
||
| error_code = "DEB0006" | ||
|
|
||
| def __init__(self, count): | ||
| super().__init__() | ||
| self.count = count | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _( | ||
| "Previous ReleaseFile count: {count}. There should only be one." | ||
| ).format(count=self.count) | ||
|
|
||
|
|
||
| class DuplicatePackageIndex(PulpException): | ||
| """ | ||
| Raised when multiple PackageIndex objects exist where only one is expected. | ||
| """ | ||
|
|
||
| error_code = "DEB0007" | ||
|
|
||
| def __init__(self, count): | ||
| super().__init__() | ||
| self.count = count | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _( | ||
| "Previous PackageIndex count: {count}. There should only be one." | ||
| ).format(count=self.count) | ||
|
|
||
|
|
||
| class SourceSyncNotSupported(PulpException): | ||
| """ | ||
| Raised when attempting to sync source repositories, which is not yet implemented. | ||
| """ | ||
|
|
||
| error_code = "DEB0008" | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _("Syncing source repositories is not yet implemented.") | ||
|
|
||
|
|
||
| class DependencySolvingNotSupported(PulpException): | ||
| """ | ||
| Raised when advanced copy with dependency solving is requested. | ||
| """ | ||
|
|
||
| error_code = "DEB0009" | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _( | ||
| "Advanced copy with dependency solving is not yet implemented." | ||
| ) | ||
|
|
||
|
|
||
| class DuplicatePackageChecksumError(PulpException): | ||
| """ | ||
| Raised when newly added packages have the same name, version, and architecture | ||
| but different checksums. | ||
| """ | ||
|
|
||
| error_code = "DEB0010" | ||
|
|
||
| def __str__(self): | ||
| return f"[{self.error_code}] " + _( | ||
| "Cannot create repository version since there are newly added packages with the " | ||
| "same name, version, and architecture, but a different checksum. If the log level " | ||
| "is DEBUG, you can find a list of affected packages in the Pulp log. You can often " | ||
| "work around this issue by restricting syncs to only those distribution component " | ||
| "combinations, that do not contain colliding duplicates!" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |
| from django.db.utils import IntegrityError | ||
| from rest_framework.exceptions import ValidationError | ||
|
|
||
| from pulpcore.plugin.exceptions import DigestValidationError | ||
| from pulpcore.plugin.exceptions import DigestValidationError, SyncError | ||
| from pulpcore.plugin.models import ( | ||
| Artifact, | ||
| ProgressReport, | ||
|
|
@@ -47,6 +47,16 @@ | |
| CHECKSUM_TYPE_MAP, | ||
| NO_MD5_WARNING_MESSAGE, | ||
| ) | ||
| from pulp_deb.app.exceptions import ( | ||
| DuplicatePackageIndex, | ||
| DuplicateReleaseFile, | ||
| MissingReleaseFileField, | ||
| NoPackageIndexFile, | ||
| NoReleaseFile, | ||
| NoValidSignatureForKey, | ||
| SourceSyncNotSupported, | ||
| UnknownNoSupportForArchitectureAllValue, | ||
| ) | ||
| from pulp_deb.app.models import ( | ||
| AptRemote, | ||
| AptRepository, | ||
|
|
@@ -73,92 +83,6 @@ | |
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class NoReleaseFile(Exception): | ||
| """ | ||
| Exception to signal, that no file representing a release is present. | ||
| """ | ||
|
|
||
| def __init__(self, url, *args, **kwargs): | ||
| """ | ||
| Exception to signal, that no file representing a release is present. | ||
| """ | ||
| super().__init__( | ||
| "Could not find a Release file at '{}', try checking the 'url' and " | ||
| "'distributions' option on your remote".format(url), | ||
| *args, | ||
| **kwargs, | ||
| ) | ||
|
|
||
|
|
||
| class NoValidSignatureForKey(Exception): | ||
| """ | ||
| Exception to signal, that verification of release file with provided GPG key fails. | ||
| """ | ||
|
|
||
| def __init__(self, url, *args, **kwargs): | ||
| """ | ||
| Exception to signal, that verification of release file with provided GPG key fails. | ||
| """ | ||
| super().__init__( | ||
| "Unable to verify any Release files from '{}' using the GPG key provided.".format(url), | ||
| *args, | ||
| **kwargs, | ||
| ) | ||
|
|
||
|
|
||
| class NoPackageIndexFile(Exception): | ||
| """ | ||
| Exception to signal, that no file representing a package index is present. | ||
| """ | ||
|
|
||
| def __init__(self, relative_dir, *args, **kwargs): | ||
| """ | ||
| Exception to signal, that no file representing a package index is present. | ||
| """ | ||
| self.relative_dir = relative_dir | ||
| message = ( | ||
| "No suitable package index files found in '{}'. If you are syncing from a partial " | ||
| "mirror, you can ignore this error for individual remotes " | ||
| "(ignore_missing_package_indices='True') or system wide " | ||
| "(FORCE_IGNORE_MISSING_PACKAGE_INDICES setting)." | ||
| ) | ||
| super().__init__(_(message).format(relative_dir), *args, **kwargs) | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class MissingReleaseFileField(Exception): | ||
| """ | ||
| Exception signifying that the upstream release file is missing a required field. | ||
| """ | ||
|
|
||
| def __init__(self, distribution, field, *args, **kwargs): | ||
| """ | ||
| The upstream release file is missing a required field. | ||
| """ | ||
| message = "The release file for distribution '{}' is missing the required field '{}'." | ||
| super().__init__(_(message).format(distribution, field), *args, **kwargs) | ||
|
|
||
|
|
||
| class UnknownNoSupportForArchitectureAllValue(Exception): | ||
| """ | ||
| Exception Signifying that the Release file contains the 'No-Support-for-Architecture-all' field, | ||
| but with a value other than 'Packages'. We interpret this as an error since this would likely | ||
| signify some unknown repo format, that pulp_deb is more likely to get wrong than right! | ||
|
Comment on lines
-145
to
-147
Member
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. Not a strong opinion, but I would keep the original class descriptions to ensure that no information was lost. |
||
| """ | ||
|
|
||
| def __init__(self, release_file_path, unknown_value, *args, **kwargs): | ||
| message = ( | ||
| "The Release file at '{}' contains the 'No-Support-for-Architecture-all' field, with " | ||
| "unknown value '{}'! pulp_deb currently only understands the value 'Packages' for " | ||
| "this field, please open an issue at https://github.com/pulp/pulp_deb/issues " | ||
| "specifying the remote you are attempting to sync, so that we can improve pulp_deb!" | ||
| ) | ||
| super().__init__(_(message).format(unknown_value), *args, **kwargs) | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| def synchronize(remote_pk, repository_pk, mirror, optimize): | ||
| """ | ||
| Sync content from the remote repository. | ||
|
|
@@ -172,15 +96,15 @@ def synchronize(remote_pk, repository_pk, mirror, optimize): | |
| optimize (bool): Optimize mode. | ||
|
|
||
| Raises: | ||
| ValueError: If the remote does not specify a URL to sync | ||
| SyncError: If the remote does not specify a URL to sync | ||
|
|
||
| """ | ||
| remote = AptRemote.objects.get(pk=remote_pk) | ||
| repository = AptRepository.objects.get(pk=repository_pk) | ||
| previous_repo_version = repository.latest_version() | ||
|
|
||
| if not remote.url: | ||
| raise ValueError(_("A remote must have a url specified to synchronize.")) | ||
| raise SyncError(_("A remote must have a url specified to synchronize.")) | ||
|
|
||
| if optimize and mirror: | ||
| skip_dist = [] | ||
|
|
@@ -902,7 +826,7 @@ async def _handle_flat_repo( | |
|
|
||
| # Handle source package index | ||
| if self.remote.sync_sources: | ||
| raise NotImplementedError("Syncing source repositories is not yet implemented.") | ||
| raise SourceSyncNotSupported() | ||
|
|
||
| # Await all tasks | ||
| await asyncio.gather(*pending_tasks) | ||
|
|
@@ -1315,8 +1239,7 @@ def get_previous_release_file(previous_version, distribution): | |
| ReleaseFile.objects.filter(distribution=distribution) | ||
| ) | ||
| if previous_release_file_qs.count() > 1: | ||
| message = "Previous ReleaseFile count: {}. There should only be one." | ||
| raise Exception(message.format(previous_release_file_qs.count())) | ||
| raise DuplicateReleaseFile(count=previous_release_file_qs.count()) | ||
| return previous_release_file_qs.first() | ||
|
|
||
|
|
||
|
|
@@ -1329,8 +1252,7 @@ def _get_previous_package_index(previous_version, relative_path): | |
| PackageIndex.objects.filter(relative_path=relative_path) | ||
| ) | ||
| if previous_package_index_qs.count() > 1: | ||
| message = "Previous PackageIndex count: {}. There should only be one." | ||
| raise Exception(message.format(previous_package_index_qs.count())) | ||
| raise DuplicatePackageIndex(count=previous_package_index_qs.count()) | ||
| return previous_package_index_qs.first() | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this something that the api allows in the first place?
I would not change this Exception at all.
If the user can trigger an Unimplemented codepath, that's a server error. And should be prevented/fixed/implemented.
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.
but does it hurt to let the user know what's caused the error?
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.
Is there any way the user can trigger this?
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.
I think the API parameter already exists, and then you will quickly learn not to use it, because it is not implemented and can never work...
Uh oh!
There was an error while loading. Please reload this page.
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.
yes, if request for copying for some reason has "dependency_solving" set to true:
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.
I'm sad now. Anyway, can we handle NotImplementedError generically in core? It looks like there would be a pattern.