fix: Improve error handling in Pulumi execute functions

This commit is contained in:
Stefan Reimer 2022-07-06 15:35:28 +02:00
parent e0c724c68f
commit f1bfbd3eea
2 changed files with 12 additions and 6 deletions

View File

@ -201,7 +201,9 @@ def execute(cb, stack_name, function, args):
for s in stacks:
if s.mode == "pulumi":
s.execute(function, args)
ret = s.execute(function, args)
if ret:
raise click.Abort()
else:
logger.info(
"{} uses Cloudformation, no execute feature available.".format(

View File

@ -894,11 +894,15 @@ class Stack(object):
exec_function = f"_execute_{function}"
if exec_function in vars(self._pulumi_code):
pulumi_stack = self._get_pulumi_stack()
vars(self._pulumi_code)[exec_function](
config=pulumi_stack.get_all_config(),
outputs=pulumi_stack.outputs(),
args=args,
)
try:
vars(self._pulumi_code)[exec_function](
config=pulumi_stack.get_all_config(),
outputs=pulumi_stack.outputs(),
args=args,
)
except Exception as e:
return e.returncode
else:
logger.error("{} is not defined in {}".format(function, self._pulumi_code))