Skip to content

Commit 0b60b4d

Browse files
authored
Merge pull request #87 from dhellmann/retry-81
Improve error message for IOErrors
2 parents 513621b + 389610e commit 0b60b4d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

virtualenvwrapper/hook_loader.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,16 @@ def main():
146146
log.debug('Saving sourcable %s hooks to %s',
147147
hook, options.script_filename)
148148
options.sourcing = True
149-
output = open(options.script_filename, "w")
150149
try:
151-
output.write('# %s\n' % hook)
152-
# output.write('echo %s\n' % hook)
153-
# output.write('set -x\n')
154-
run_hooks(hook + '_source', options, args, output)
155-
finally:
156-
output.close()
150+
with open(options.script_filename, "w") as output:
151+
output.write('# %s\n' % hook)
152+
# output.write('echo %s\n' % hook)
153+
# output.write('set -x\n')
154+
run_hooks(hook + '_source', options, args, output)
155+
except (IOError, OSError) as e:
156+
log.error('Error while writing to %s: \n %s',
157+
options.script_filename, e)
158+
sys.exit(1)
157159

158160
return 0
159161

0 commit comments

Comments
 (0)