overall better handling and usage of exceptions
All checks were successful
bundlewrap/pipeline/head This commit looks good

This commit is contained in:
Franzi 2021-04-02 18:57:13 +02:00
parent 5d5930265a
commit f8bbe00d47
Signed by: kunsi
GPG key ID: 12E3D2136B818350
21 changed files with 57 additions and 28 deletions

View file

@ -1,6 +1,6 @@
from ipaddress import ip_address, ip_network, IPv4Address, IPv4Network
from bundlewrap.exceptions import NoSuchGroup, NoSuchNode
from bundlewrap.exceptions import NoSuchGroup, NoSuchNode, BundleError
from bundlewrap.utils.text import bold, red
from bundlewrap.utils.ui import io
@ -78,3 +78,11 @@ def remove_more_specific_subnets(input_subnets) -> list:
out.append(str(net))
return out
def require_bundle(node, bundle, hint=''):
# It's considered bad style to use assert statements outside of tests.
# That's why this little helper function exists, so we have an easy
# way of defining bundle requirements in other bundles.
if not node.has_bundle(bundle):
raise BundleError(f'{node.name} requires bundle {bundle}, but wasn\'t found! {hint}')