Add and use throw_if_invalid function
Validates objects and raises an error if they are invalid
This commit is contained in:
parent
35a5a69844
commit
b6b283d2b2
2 changed files with 6 additions and 3 deletions
|
@ -18,6 +18,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):
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue