Add and use throw_if_invalid function

Validates objects and raises an error if they are invalid
This commit is contained in:
bom 2023-04-28 13:33:54 +02:00 committed by Michael Jerger
parent 35a5a69844
commit b6b283d2b2
2 changed files with 6 additions and 3 deletions

View file

@ -19,6 +19,11 @@ class Validateable:
def is_valid(self) -> bool: def is_valid(self) -> bool:
return len(self.validate()) < 1 return len(self.validate()) < 1
def throw_if_invalid(self):
if not self.is_valid():
issues = '\n'.join(self.validate())
raise ValueError(f"Invalid Validateable: {issues}")
class DnsRecord(Validateable): class DnsRecord(Validateable):
def __init__(self, fqdn, ipv4=None, ipv6=None): def __init__(self, fqdn, ipv4=None, ipv6=None):

View file

@ -124,7 +124,5 @@ class ReleaseContextRepository:
self.version_repository.get_version(), self.version_repository.get_version(),
self.main_branch, self.main_branch,
) )
if not result.is_valid(): result.throw_if_invalid()
issues = '\n'.join(result.validate())
raise ValueError(f"invalid release: {issues}")
return result return result