From c7370522cc73a0c8924140604c6bd6d9d1481657 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Tue, 20 Sep 2022 11:30:59 +0200 Subject: [PATCH] Add PackageError.__str__() so we can also use it in the inherited classes --- osc/oscerr.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/osc/oscerr.py b/osc/oscerr.py index 7caa7eb5..9df3de89 100644 --- a/osc/oscerr.py +++ b/osc/oscerr.py @@ -120,28 +120,30 @@ class WorkingCopyOutdated(OscBaseError): class PackageError(OscBaseError): """Base class for all Package related exceptions""" - def __init__(self, prj, pac): + def __init__(self, prj, pac, msg=None): super().__init__() self.prj = prj self.pac = pac + self.msg = msg + + def __str__(self): + result = f"{self.__class__.__name__}: {self.prj}/{self.pac}" + if self.msg: + result += f": {self.msg}" + return result class WorkingCopyInconsistent(PackageError): """Exception raised when the working copy is in an inconsistent state""" def __init__(self, prj, pac, dirty_files, msg): - super().__init__(prj, pac) + super().__init__(prj, pac, msg) self.dirty_files = dirty_files - self.msg = msg class LinkExpandError(PackageError): """Exception raised when source link expansion fails""" - def __init__(self, prj, pac, msg): - super().__init__(prj, pac) - self.msg = msg - class OscIOError(OscBaseError): def __init__(self, e, msg): @@ -187,20 +189,12 @@ class PackageExists(PackageError): Exception raised when a local object already exists """ - def __init__(self, prj, pac, msg): - super().__init__(prj, pac) - self.msg = msg - class PackageMissing(PackageError): """ Exception raised when a local object doesn't exist """ - def __init__(self, prj, pac, msg): - super().__init__(prj, pac) - self.msg = msg - class PackageFileConflict(PackageError): """ @@ -209,13 +203,12 @@ class PackageFileConflict(PackageError): """ def __init__(self, prj, pac, file, msg): - super().__init__(prj, pac) + super().__init__(prj, pac, msg) self.file = file - self.msg = msg class PackageInternalError(PackageError): - def __init__(self, prj, pac, msg): - super().__init__(prj, pac) - self.msg = msg + pass + + # vim: sw=4 et