Skip to content

Commit 477ecbc

Browse files
committed
Raise exception for validate
Problem: Currently, an exception is not raised if the `validate` method is called, even when there are errors and the validation fails. Consequently, the cli module does not catch an exception and the courier does not modify its exit code from 0 when the `validate` method is used. `operator-courier` should return a non zero exit code when the input is invalid. Fix: Raise a ValueError in the build_and_verify method when the bundle isn't valid. Remove the empty bundle check in the push method, since the underlying build_and_verify method will raise the necessary exception Fixes https://github.com/operator-framework/operator-courier/issues/46V
1 parent f46acd4 commit 477ecbc

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

operatorcourier/api.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def build_and_verify(source_dir=None, yamls=None, ui_validate_io=False):
5151
if not valid:
5252
bundle = None
5353
logger.error("Bundle failed validation.")
54+
raise ValueError("Resulting bundle is invalid, input yaml is improperly defined.")
5455
else:
5556
bundle = format_bundle(bundle)
5657

@@ -74,17 +75,14 @@ def build_verify_and_push(namespace, repository, revision, token,
7475

7576
bundle = build_and_verify(source_dir, yamls)
7677

77-
if bundle is not None:
78-
with TemporaryDirectory() as temp_dir:
79-
with open('%s/bundle.yaml' % temp_dir, 'w') as outfile:
80-
yaml.dump(bundle, outfile, default_flow_style=False)
81-
outfile.flush()
78+
bundle = build_and_verify(source_dir, yamls)
79+
80+
with TemporaryDirectory() as temp_dir:
81+
with open('%s/bundle.yaml' % temp_dir, 'w') as outfile:
82+
yaml.dump(bundle, outfile, default_flow_style=False)
83+
outfile.flush()
8284

83-
PushCmd().push(temp_dir, namespace, repository, revision, token)
84-
else:
85-
logger.error("Bundle is invalid. Will not attempt to push.")
86-
raise ValueError(
87-
"Resulting bundle is invalid, input yaml is improperly defined.")
85+
PushCmd().push(temp_dir, namespace, repository, revision, token)
8886

8987

9088
def nest(source_dir, registry_dir):

0 commit comments

Comments
 (0)