Add and use throw_if_invalid function
Validates objects and raises an error if they are invalid
This commit is contained in:
parent
61d99a7b12
commit
f4fed5293a
2 changed files with 6 additions and 3 deletions
|
@ -19,6 +19,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):
|
||||
def __init__(self, fqdn, ipv4=None, ipv6=None):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue