From 057b7e1e90069c8e1f442af2eae609a7ed416144 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Tue, 16 Mar 2021 09:40:44 +0100 Subject: [PATCH] [FIX] Propagate exception when git url does not match * 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 --- src/mr/developer/common.py | 9 ++++++++- src/mr/developer/git.py | 8 +++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/mr/developer/common.py b/src/mr/developer/common.py index 6520ec7..b737514 100644 --- a/src/mr/developer/common.py +++ b/src/mr/developer/common.py @@ -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) @@ -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 diff --git a/src/mr/developer/git.py b/src/mr/developer/git.py index 0ed6fa8..87e7b70 100644 --- a/src/mr/developer/git.py +++ b/src/mr/developer/git.py @@ -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() @@ -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)