Skip to content

Commit

Permalink
Improve error messages
Browse files Browse the repository at this point in the history
Don't crash with a python traceback when remove or rename
fails in builder.py. Instead, print a redo-style error
message and halt with an error code.
  • Loading branch information
bocchino committed Dec 9, 2016
1 parent a0b88e0 commit 7fd7727
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions lib/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def done(t, rv):
# Target locked by parent: cyclic dependence
err('encountered a dependence cycle:\n')
_print_cycle(target_list, nice_t)
retcode[0] = 208
retcode[0] = 209
break
lock = state.Lock(fid)
lock.trylock()
Expand Down Expand Up @@ -299,15 +299,19 @@ def _after1(self, t, rv):
err('...you should write status messages to stderr, not stdout.\n')
rv = 207
if rv==0:
if st2:
_rename(self.tmpname2, t)
_remove(self.tmpname1)
elif st1.st_size > 0:
_rename(self.tmpname1, t)
else: # no output generated at all; that's ok
_remove(self.tmpname1)
if os.path.isfile(t):
_remove(t)
try:
if st2:
_rename(self.tmpname2, t)
_remove(self.tmpname1)
elif st1.st_size > 0:
_rename(self.tmpname1, t)
else: # no output generated at all; that's ok
_remove(self.tmpname1)
if os.path.isfile(t):
_remove(t)
except:
rv=208
if rv == 0:
sf = self.sf
sf.refresh()
sf.is_generated = True
Expand Down Expand Up @@ -349,17 +353,25 @@ def _after2(self, rv):

def _remove(path):
if os.path.isdir(path) and len(os.listdir(path)) > 0:
warn('directory %s is nonempty; not redoing\n' % path)
warn('directory %s is nonempty; not redoing\n' % _nice(path))
return False
else:
remove(path)
try:
remove(path)
except:
err('failed attempting to remove %s\n' % _nice(path))
raise
return True


def _rename(src, dest):
status = _remove(dest)
if status:
rename(src, dest)
try:
rename(src, dest)
except:
err('failed attempting to rename %s to %s\n' % (_nice(src), _nice(dest)))
raise
return status


Expand Down

0 comments on commit 7fd7727

Please sign in to comment.