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
parent 61d99a7b12
commit f4fed5293a
2 changed files with 6 additions and 3 deletions

View file

@ -18,6 +18,11 @@ class Validateable:
def is_valid(self) -> bool:
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):

View file

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