Skip to content

Commit 633d6be

Browse files
author
Aliaksei Klimau
committed
New exception class for declarative artifact init errors added
1 parent 43966ea commit 633d6be

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

pulpcore/exceptions/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
DnsDomainNameException,
88
ImmediateTaskTimeoutError,
99
NonAsyncImmediateTaskError,
10+
DeclarativeArtifactValidationError,
1011
)
1112
from .validation import (
1213
DigestValidationError,

pulpcore/exceptions/base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,20 @@ def __str__(self):
155155
return _("Immediate task '{task_name}' must be an async function.").format(
156156
task_name=self.task_name
157157
)
158+
159+
160+
class DeclarativeArtifactValidationError(PulpException):
161+
"""
162+
Exception raised when DeclarativeArtifact validation fails during initialization.
163+
"""
164+
165+
def __init__(self, message):
166+
"""
167+
:param message: A translated string describing the specific validation failure.
168+
:type message: str
169+
"""
170+
super().__init__("PLP0011")
171+
self.message = message
172+
173+
def __str__(self):
174+
return self.message

pulpcore/plugin/stages/models.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from pulpcore.constants import ALL_KNOWN_CONTENT_CHECKSUMS
66
from pulpcore.plugin.models import Artifact
7+
from pulpcore.exceptions import DeclarativeArtifactValidationError
78

89

910
class DeclarativeArtifact:
@@ -33,7 +34,7 @@ class DeclarativeArtifact:
3334
in the artifact stages. Defaults to `False`. See :ref:`on-demand-support`.
3435
3536
Raises:
36-
ValueError: If `artifact`, `url`, or `relative_path` are not specified. If `remote` is not
37+
DeclarativeArtifactValidationError: If `artifact`, `url`, or `relative_path` are not specified. If `remote` is not
3738
specified and `artifact` doesn't have a file.
3839
"""
3940

@@ -57,15 +58,27 @@ def __init__(
5758
deferred_download=False,
5859
):
5960
if not (url or urls):
60-
raise ValueError(_("DeclarativeArtifact must have a at least one 'url' provided"))
61+
raise DeclarativeArtifactValidationError(
62+
_("DeclarativeArtifact must have a at least one 'url' provided")
63+
)
64+
6165
if url and urls:
62-
raise ValueError(_("DeclarativeArtifact must not provide both 'url' and 'urls'"))
66+
raise DeclarativeArtifactValidationError(
67+
_("DeclarativeArtifact must not provide both 'url' and 'urls'")
68+
)
69+
6370
if not relative_path:
64-
raise ValueError(_("DeclarativeArtifact must have a 'relative_path'"))
71+
raise DeclarativeArtifactValidationError(
72+
_("DeclarativeArtifact must have a 'relative_path'")
73+
)
74+
6575
if not artifact:
66-
raise ValueError(_("DeclarativeArtifact must have a 'artifact'"))
76+
raise DeclarativeArtifactValidationError(
77+
_("DeclarativeArtifact must have a 'artifact'")
78+
)
79+
6780
if not remote and not artifact.file:
68-
raise ValueError(
81+
raise DeclarativeArtifactValidationError(
6982
_(
7083
"DeclarativeArtifact must have a 'remote' if the Artifact doesn't "
7184
"have a file backing it."

0 commit comments

Comments
 (0)