Skip to content

Commit

Permalink
[FIX] Propagate exception when git url does not match
Browse files Browse the repository at this point in the history
* Don't drop exception silently (and continue) when it occurs in a forked off thread
* Raise, not exit on unknown git branch
* Raise when git url does not match
  • Loading branch information
StefanRijnhart committed Mar 16, 2021
1 parent 51501af commit 057b7e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/mr/developer/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def worker(working_copies, the_queue):
return
try:
output = action(**kwargs)
except WCError:
except WCError as e:
threading.current_thread().exc = e
output_lock.acquire()
for lvl, msg in wc._output:
lvl(msg)
Expand Down Expand Up @@ -259,6 +260,12 @@ def _cleanup():
thread.start()
threads.append(thread)
for thread in threads:
exc = None
if hasattr(thread, "exc"):
exc = thread.exc
delattr(thread, "exc")
if exc:
raise thread.exc
thread.join()
if sys.version_info < (2, 6):
subprocess._cleanup = _old_subprocess_cleanup
Expand Down
8 changes: 5 additions & 3 deletions src/mr/developer/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ def git_switch_branch(self, stdout_in, stderr_in, accept_missing=False):
return (stdout_in + stdout,
stderr_in + stderr)
else:
self.output((logger.error, "No such branch %r", branch))
sys.exit(1)
raise GitError("No such branch %r" % branch)
# runs the checkout with predetermined arguments
cmd = self.run_git(argv, cwd=path)
stdout, stderr = cmd.communicate()
Expand Down Expand Up @@ -288,7 +287,10 @@ def matches(self):
def update(self, **kwargs):
name = self.source['name']
if not self.matches():
self.output((logger.warning, "Can't update package '%s' because its URL doesn't match." % name))
message = "Can't update package '%s' because its URL doesn't match." % name
if kwargs.get("force"):
raise GitError(message)
self.output((logger.warning, message))
if self.status() != 'clean' and not kwargs.get('force', False):
raise GitError("Can't update package '%s' because it's dirty." % name)
return self.git_update(**kwargs)
Expand Down

0 comments on commit 057b7e1

Please sign in to comment.