From 41c51ceade951fd78088192631811de56b74ec98 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: May 03 2022 12:21:47 +0000 Subject: [PATCH 1/4] refactor exceptions to koji.exceptions Move Koji's custom exceptions classes to a dedicated koji.exceptions library. This organizes the code so it's easier to maintain, and matches patterns in other well-known projects, like requests.exceptions or cryptography.exceptions. --- diff --git a/koji/__init__.py b/koji/__init__.py index 348f060..d96bb5c 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -76,6 +76,34 @@ from . import _version __version__ = _version.__version__ __version_info__ = _version.__version_info__ +from koji.exceptions import ( + PythonImportError, + GenericError, + LockError, + AuthError, + TagError, + ActionNotAllowed, + BuildError, + AuthLockError, + AuthExpired, + SequenceError, + RetryError, + PreBuildError, + PostBuildError, + BuildrootError, + FunctionDeprecated, + ServerOffline, + LiveCDError, + PluginError, + CallbackError, + ApplianceError, + ParameterError, + ImportError, + ConfigurationError, + LiveMediaError, + GSSAPIAuthError, +) + try: import requests_gssapi as reqgssapi except ImportError: # pragma: no cover @@ -292,145 +320,6 @@ PRIO_DEFAULT = 20 DEFAULT_REQUEST_TIMEOUT = 60 * 60 * 12 DEFAULT_AUTH_TIMEOUT = 60 -# BEGIN kojikamid dup # - -# Exceptions -PythonImportError = ImportError # will be masked by koji's one - - -class GenericError(Exception): - """Base class for our custom exceptions""" - faultCode = 1000 - fromFault = False - - def __str__(self): - try: - return str(self.args[0]['args'][0]) - except Exception: - try: - return str(self.args[0]) - except Exception: - return str(self.__dict__) -# END kojikamid dup # - - -class LockError(GenericError): - """Raised when there is a lock conflict""" - faultCode = 1001 - - -class AuthError(GenericError): - """Raised when there is an error in authentication""" - faultCode = 1002 - - -class TagError(GenericError): - """Raised when a tagging operation fails""" - faultCode = 1003 - - -class ActionNotAllowed(GenericError): - """Raised when the session does not have permission to take some action""" - faultCode = 1004 - -# BEGIN kojikamid dup # - - -class BuildError(GenericError): - """Raised when a build fails""" - faultCode = 1005 -# END kojikamid dup # - - -class AuthLockError(AuthError): - """Raised when a lock prevents authentication""" - faultCode = 1006 - - -class AuthExpired(AuthError): - """Raised when a session has expired""" - faultCode = 1007 - - -class SequenceError(AuthError): - """Raised when requests are received out of sequence""" - faultCode = 1008 - - -class RetryError(AuthError): - """Raised when a request is received twice and cannot be rerun""" - faultCode = 1009 - - -class PreBuildError(BuildError): - """Raised when a build fails during pre-checks""" - faultCode = 1010 - - -class PostBuildError(BuildError): - """Raised when a build fails during post-checks""" - faultCode = 1011 - - -class BuildrootError(BuildError): - """Raised when there is an error with the buildroot""" - faultCode = 1012 - - -class FunctionDeprecated(GenericError): - """Raised by a deprecated function""" - faultCode = 1013 - - -class ServerOffline(GenericError): - """Raised when the server is offline""" - faultCode = 1014 - - -class LiveCDError(GenericError): - """Raised when LiveCD Image creation fails""" - faultCode = 1015 - - -class PluginError(GenericError): - """Raised when there is an error with a plugin""" - faultCode = 1016 - - -class CallbackError(PluginError): - """Raised when there is an error executing a callback""" - faultCode = 1017 - - -class ApplianceError(GenericError): - """Raised when Appliance Image creation fails""" - faultCode = 1018 - - -class ParameterError(GenericError): - """Raised when an rpc call receives incorrect arguments""" - faultCode = 1019 - - -class ImportError(GenericError): - """Raised when an import fails""" - faultCode = 1020 - - -class ConfigurationError(GenericError): - """Raised when load of koji configuration fails""" - faultCode = 1021 - - -class LiveMediaError(GenericError): - """Raised when LiveMedia Image creation fails""" - faultCode = 1022 - - -class GSSAPIAuthError(AuthError): - """Raised when GSSAPI issue in authentication""" - faultCode = 1023 - class NameValidationError(GenericError): """Raised when name validation fails diff --git a/koji/exceptions.py b/koji/exceptions.py new file mode 100644 index 0000000..67f2a08 --- /dev/null +++ b/koji/exceptions.py @@ -0,0 +1,132 @@ +# Exceptions +PythonImportError = ImportError # will be masked by koji's one + + +class GenericError(Exception): + """Base class for our custom exceptions""" + faultCode = 1000 + fromFault = False + + def __str__(self): + try: + return str(self.args[0]['args'][0]) + except Exception: + try: + return str(self.args[0]) + except Exception: + return str(self.__dict__) + + +class LockError(GenericError): + """Raised when there is a lock conflict""" + faultCode = 1001 + + +class AuthError(GenericError): + """Raised when there is an error in authentication""" + faultCode = 1002 + + +class TagError(GenericError): + """Raised when a tagging operation fails""" + faultCode = 1003 + + +class ActionNotAllowed(GenericError): + """Raised when the session does not have permission to take some action""" + faultCode = 1004 + + +class BuildError(GenericError): + """Raised when a build fails""" + faultCode = 1005 + + +class AuthLockError(AuthError): + """Raised when a lock prevents authentication""" + faultCode = 1006 + + +class AuthExpired(AuthError): + """Raised when a session has expired""" + faultCode = 1007 + + +class SequenceError(AuthError): + """Raised when requests are received out of sequence""" + faultCode = 1008 + + +class RetryError(AuthError): + """Raised when a request is received twice and cannot be rerun""" + faultCode = 1009 + + +class PreBuildError(BuildError): + """Raised when a build fails during pre-checks""" + faultCode = 1010 + + +class PostBuildError(BuildError): + """Raised when a build fails during post-checks""" + faultCode = 1011 + + +class BuildrootError(BuildError): + """Raised when there is an error with the buildroot""" + faultCode = 1012 + + +class FunctionDeprecated(GenericError): + """Raised by a deprecated function""" + faultCode = 1013 + + +class ServerOffline(GenericError): + """Raised when the server is offline""" + faultCode = 1014 + + +class LiveCDError(GenericError): + """Raised when LiveCD Image creation fails""" + faultCode = 1015 + + +class PluginError(GenericError): + """Raised when there is an error with a plugin""" + faultCode = 1016 + + +class CallbackError(PluginError): + """Raised when there is an error executing a callback""" + faultCode = 1017 + + +class ApplianceError(GenericError): + """Raised when Appliance Image creation fails""" + faultCode = 1018 + + +class ParameterError(GenericError): + """Raised when an rpc call receives incorrect arguments""" + faultCode = 1019 + + +class ImportError(GenericError): + """Raised when an import fails""" + faultCode = 1020 + + +class ConfigurationError(GenericError): + """Raised when load of koji configuration fails""" + faultCode = 1021 + + +class LiveMediaError(GenericError): + """Raised when LiveMedia Image creation fails""" + faultCode = 1022 + + +class GSSAPIAuthError(AuthError): + """Raised when GSSAPI issue in authentication""" + faultCode = 1023 From 9379a2a07ad90b7ceb0c7931751aec998288fb28 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: May 03 2022 12:26:15 +0000 Subject: [PATCH 2/4] add "NoSuch" custom exceptions Add more custom exception classes. This will allow to programmatically determine the error causes from complex RPCs. This commit simply defines the new classes and fault codes. Nothing in Koji's codebase uses these exceptions yet. We'll begin to raise these exceptions after this is widely deployed for clients in the field. --- diff --git a/koji/exceptions.py b/koji/exceptions.py index 67f2a08..d5f1537 100644 --- a/koji/exceptions.py +++ b/koji/exceptions.py @@ -130,3 +130,51 @@ class LiveMediaError(GenericError): class GSSAPIAuthError(AuthError): """Raised when GSSAPI issue in authentication""" faultCode = 1023 + + +class NoSuchArchive(object): + faultCode = 1024 + + +class NoSuchBuild(object): + faultCode = 1025 + + +class NoSuchChannel(object): + faultCode = 1026 + + +class NoSuchContentGenerator(object): + faultCode = 1027 + + +class NoSuchPackage(object): + faultCode = 1028 + + +class NoSuchPermission(object): + faultCode = 1029 + + +class NoSuchRPM(object): + faultCode = 1030 + + +class NoSuchRepo(object): + faultCode = 1031 + + +class NoSuchTag(object): + faultCode = 1032 + + +class NoSuchTarget(object): + faultCode = 1033 + + +class NoSuchTask(object): + faultCode = 1034 + + +class NoSuchUser(object): + faultCode = 1035 From aba17ec8e762ebde79c1309a0de08251394d42dc Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: May 03 2022 12:26:15 +0000 Subject: [PATCH 3/4] fix kojikamid preprocessor --- diff --git a/koji/exceptions.py b/koji/exceptions.py index d5f1537..bd10427 100644 --- a/koji/exceptions.py +++ b/koji/exceptions.py @@ -1,7 +1,11 @@ + # Exceptions PythonImportError = ImportError # will be masked by koji's one +# BEGIN kojikamid dup # + + class GenericError(Exception): """Base class for our custom exceptions""" faultCode = 1000 @@ -15,6 +19,7 @@ class GenericError(Exception): return str(self.args[0]) except Exception: return str(self.__dict__) +# END kojikamid dup # class LockError(GenericError): @@ -37,9 +42,13 @@ class ActionNotAllowed(GenericError): faultCode = 1004 +# BEGIN kojikamid dup # + + class BuildError(GenericError): """Raised when a build fails""" faultCode = 1005 +# END kojikamid dup # class AuthLockError(AuthError): diff --git a/vm/fix_kojikamid.sh b/vm/fix_kojikamid.sh index 12c3acd..526c59a 100755 --- a/vm/fix_kojikamid.sh +++ b/vm/fix_kojikamid.sh @@ -2,7 +2,7 @@ awk '/^# INSERT kojikamid dup #/ {exit} {print $0}' kojikamid.py -for fn in ../koji/__init__.py ../koji/daemon.py ../koji/util.py +for fn in ../koji/exceptions.py ../koji/__init__.py ../koji/daemon.py ../koji/util.py do awk '/^# END kojikamid dup #/ {p=0} p {print $0} /^# BEGIN kojikamid dup #/ {p=1}' $fn done From 3b8c3a3f2b1ae09bf45f1eb536328730ab881177 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: May 03 2022 12:29:05 +0000 Subject: [PATCH 4/4] add base NoSuchItem exception As we don't have all the NoSuchX exceptions for current data nor for the future ones, base class could be used to catch all such exceptions. --- diff --git a/koji/exceptions.py b/koji/exceptions.py index bd10427..62810ad 100644 --- a/koji/exceptions.py +++ b/koji/exceptions.py @@ -141,49 +141,53 @@ class GSSAPIAuthError(AuthError): faultCode = 1023 -class NoSuchArchive(object): +class NoSuchItem(GenericError): faultCode = 1024 -class NoSuchBuild(object): +class NoSuchArchive(NoSuchItem): faultCode = 1025 -class NoSuchChannel(object): +class NoSuchBuild(NoSuchItem): faultCode = 1026 -class NoSuchContentGenerator(object): +class NoSuchChannel(NoSuchItem): faultCode = 1027 -class NoSuchPackage(object): +class NoSuchContentGenerator(NoSuchItem): faultCode = 1028 -class NoSuchPermission(object): +class NoSuchPackage(NoSuchItem): faultCode = 1029 -class NoSuchRPM(object): +class NoSuchPermission(NoSuchItem): faultCode = 1030 -class NoSuchRepo(object): +class NoSuchRPM(NoSuchItem): faultCode = 1031 -class NoSuchTag(object): +class NoSuchRepo(NoSuchItem): faultCode = 1032 -class NoSuchTarget(object): +class NoSuchTag(NoSuchItem): faultCode = 1033 -class NoSuchTask(object): +class NoSuchTarget(NoSuchItem): faultCode = 1034 -class NoSuchUser(object): +class NoSuchTask(NoSuchItem): faultCode = 1035 + + +class NoSuchUser(NoSuchItem): + faultCode = 1036