Skip to content

Commit 4b1b74f

Browse files
committed
Fix possible NameError in SubProcessCompiler.execute_command()
If creating the NamedTemporaryFile throws an exception (for instance if temp_file_container doesn't exist) this triggers a NameError in the finally block.
1 parent 7f4b298 commit 4b1b74f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pipeline/compilers/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def execute_command(self, command, cwd=None, stdout_captured=None):
111111
else:
112112
argument_list.extend(flattening_arg)
113113

114+
stdout = None
114115
try:
115116
# We always catch stdout in a file, but we may not have a use for it.
116117
temp_file_container = cwd or os.path.dirname(stdout_captured or "") or os.getcwd()
@@ -134,8 +135,9 @@ def execute_command(self, command, cwd=None, stdout_captured=None):
134135
stdout_captured = None # Don't save erroneous result.
135136
raise CompilerError(e)
136137
finally:
137-
# Decide what to do with captured stdout.
138-
if stdout_captured:
139-
os.rename(stdout.name, os.path.join(cwd or os.curdir, stdout_captured))
140-
else:
141-
os.remove(stdout.name)
138+
if stdout:
139+
# Decide what to do with captured stdout.
140+
if stdout_captured:
141+
os.rename(stdout.name, os.path.join(cwd or os.curdir, stdout_captured))
142+
else:
143+
os.remove(stdout.name)

0 commit comments

Comments
 (0)