Skip to content

Commit acd69dd

Browse files
committed
Add error handling and formatting for assemble_cluster_template
Signed-off-by: Webster Mudge <[email protected]>
1 parent c3e5093 commit acd69dd

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

plugins/action/assemble_cluster_template.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
3-
41
# Copyright 2023 Cloudera, Inc.
52
#
63
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -189,7 +186,12 @@ def run(self, tmp=None, task_vars=None):
189186
# Compile the regexp
190187
compiled = None
191188
if regexp is not None:
192-
compiled = re.compile(regexp)
189+
try:
190+
compiled = re.compile(regexp)
191+
except re.error as e:
192+
raise AnsibleActionFail(
193+
message=f"Regular expression, {regexp}, is invalid: {to_native(e)}"
194+
)
193195

194196
# Assemble the src files into output file
195197
with tempfile.NamedTemporaryFile(
@@ -231,15 +233,15 @@ def run(self, tmp=None, task_vars=None):
231233

232234
if assembled_checksum != dest_stat["checksum"]:
233235
diff = {}
234-
236+
235237
if self._task.diff:
236238
diff = self._get_diff_data(dest, assembled.name, task_vars)
237239

238240
# Define a temporary remote path for the remote copy
239241
remote_path = self._connection._shell.join_path(
240242
self._connection._shell.tmpdir, "assembled_cluster_template"
241243
)
242-
244+
243245
# Transfer the file to the remote path
244246
transfered = self._transfer_file(assembled.name, remote_path)
245247

@@ -262,7 +264,7 @@ def run(self, tmp=None, task_vars=None):
262264

263265
if diff:
264266
copy.update(diff=diff)
265-
267+
266268
result.update(copy)
267269
else:
268270
# Gather details on the existing file
@@ -271,7 +273,7 @@ def run(self, tmp=None, task_vars=None):
271273
module_args=submodule_args,
272274
task_vars=task_vars,
273275
)
274-
276+
275277
result.update(file)
276278
except AnsibleAction as e:
277279
result.update(e.result)

0 commit comments

Comments
 (0)