Skip to content

Commit 15062c7

Browse files
kerel-fsdhellmann
authored andcommitted
Improve error message for IOErrors
1 parent 0332d4a commit 15062c7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

virtualenvwrapper/hook_loader.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,15 @@ 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', options.script_filename, e)
157+
sys.exit(1)
157158

158159
return 0
159160

0 commit comments

Comments
 (0)