1818from django .conf import settings
1919from django .db .utils import IntegrityError
2020
21- from pulpcore .plugin .exceptions import DigestValidationError
21+ from pulpcore .plugin .exceptions import DigestValidationError , PulpException
2222from rest_framework .exceptions import ValidationError
2323
2424
8080log = logging .getLogger (__name__ )
8181
8282
83- class NoReleaseFile (Exception ):
83+ class DebException (PulpException ):
84+ """
85+ Base class for expected sync failures.
86+ """
87+
88+ error_code = "DEB0000"
89+
90+ def __init__ (self , message , details = None ):
91+ super ().__init__ ()
92+ self .message = message
93+ self .details = details
94+
95+ def __str__ (self ):
96+ return f"[{ self .error_code } ] { self .message } "
97+
98+
99+ class NoReleaseFile (DebException ):
84100 """
85101 Exception to signal, that no file representing a release is present.
86102 """
87103
104+ error_code = "DEB0001"
105+
88106 def __init__ (self , url , * args , ** kwargs ):
89107 """
90108 Exception to signal, that no file representing a release is present.
91109 """
92110 super ().__init__ (
93111 "Could not find a Release file at '{}', try checking the 'url' and "
94112 "'distributions' option on your remote" .format (url ),
95- * args ,
96- ** kwargs ,
97113 )
98114
99115
100- class NoValidSignatureForKey (Exception ):
116+ class NoValidSignatureForKey (DebException ):
101117 """
102118 Exception to signal, that verification of release file with provided GPG key fails.
103119 """
104120
121+ error_code = "DEB0002"
122+
105123 def __init__ (self , url , * args , ** kwargs ):
106124 """
107125 Exception to signal, that verification of release file with provided GPG key fails.
108126 """
109127 super ().__init__ (
110128 "Unable to verify any Release files from '{}' using the GPG key provided." .format (url ),
111- * args ,
112- ** kwargs ,
113129 )
114130
115131
116- class NoPackageIndexFile (Exception ):
132+ class NoPackageIndexFile (DebException ):
117133 """
118134 Exception to signal, that no file representing a package index is present.
119135 """
120136
137+ error_code = "DEB0003"
138+
121139 def __init__ (self , relative_dir , * args , ** kwargs ):
122140 """
123141 Exception to signal, that no file representing a package index is present.
@@ -129,41 +147,41 @@ def __init__(self, relative_dir, *args, **kwargs):
129147 "(ignore_missing_package_indices='True') or system wide "
130148 "(FORCE_IGNORE_MISSING_PACKAGE_INDICES setting)."
131149 )
132- super ().__init__ (_ (message ).format (relative_dir ), * args , ** kwargs )
133-
134- pass
150+ super ().__init__ (_ (message ).format (relative_dir ))
135151
136152
137- class MissingReleaseFileField (Exception ):
153+ class MissingReleaseFileField (DebException ):
138154 """
139155 Exception signifying that the upstream release file is missing a required field.
140156 """
141157
158+ error_code = "DEB0004"
159+
142160 def __init__ (self , distribution , field , * args , ** kwargs ):
143161 """
144162 The upstream release file is missing a required field.
145163 """
146164 message = "The release file for distribution '{}' is missing the required field '{}'."
147- super ().__init__ (_ (message ).format (distribution , field ), * args , ** kwargs )
165+ super ().__init__ (_ (message ).format (distribution , field ))
148166
149167
150- class UnknownNoSupportForArchitectureAllValue (Exception ):
168+ class UnknownNoSupportForArchitectureAllValue (DebException ):
151169 """
152170 Exception Signifying that the Release file contains the 'No-Support-for-Architecture-all' field,
153171 but with a value other than 'Packages'. We interpret this as an error since this would likely
154172 signify some unknown repo format, that pulp_deb is more likely to get wrong than right!
155173 """
156174
175+ error_code = "DEB0005"
176+
157177 def __init__ (self , release_file_path , unknown_value , * args , ** kwargs ):
158178 message = (
159179 "The Release file at '{}' contains the 'No-Support-for-Architecture-all' field, with "
160180 "unknown value '{}'! pulp_deb currently only understands the value 'Packages' for "
161181 "this field, please open an issue at https://github.com/pulp/pulp_deb/issues "
162182 "specifying the remote you are attempting to sync, so that we can improve pulp_deb!"
163183 )
164- super ().__init__ (_ (message ).format (unknown_value ), * args , ** kwargs )
165-
166- pass
184+ super ().__init__ (_ (message ).format (release_file_path , unknown_value ))
167185
168186
169187def synchronize (remote_pk , repository_pk , mirror , optimize ):
0 commit comments