Commit c0937f1a by David Trowbridge

Fix an UnboundLocalError if a compiler fails.

Depending on where an exception is raised inside a compiler's
`execute_command`, the `stdout` variable may not be assigned. In this case, the
finally handler would fail with an `UnboundLocalError`, hiding the true cause
of the exception. This change adds a new variable, `stdout_name`, which is
populated once we've actually created the file. After this, the `CompilerError`
is successfully raised with the contents of the true error.
parent 0db06ec1
......@@ -112,9 +112,12 @@ class SubProcessCompiler(CompilerBase):
argument_list.extend(flattening_arg)
try:
stdout_name = None
# We always catch stdout in a file, but we may not have a use for it.
temp_file_container = cwd or os.path.dirname(stdout_captured or "") or os.getcwd()
with NamedTemporaryFile(delete=False, dir=temp_file_container) as stdout:
stdout_name = stdout.name
compiling = subprocess.Popen(argument_list, cwd=cwd,
stdout=stdout,
stderr=subprocess.PIPE)
......@@ -135,7 +138,8 @@ class SubProcessCompiler(CompilerBase):
raise CompilerError(e)
finally:
# Decide what to do with captured stdout.
if stdout_captured:
os.rename(stdout.name, os.path.join(cwd or os.curdir, stdout_captured))
else:
os.remove(stdout.name)
if stdout_name:
if stdout_captured:
os.rename(stdout_name, os.path.join(cwd or os.curdir, stdout_captured))
else:
os.remove(stdout_name)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment