From 662ace8deabd34558481177946190266db767547 Mon Sep 17 00:00:00 2001 From: Jeffrey Kelling Date: Thu, 12 Jan 2023 10:59:45 +0100 Subject: [PATCH 1/3] HermesHarvestContext.__exit__: log.warning on HermesValidationError git harvester: raise HermesValidationError insead of runtime error when git commands fail --- src/hermes/commands/harvest/git.py | 10 ++++++---- src/hermes/model/context.py | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/hermes/commands/harvest/git.py b/src/hermes/commands/harvest/git.py index 2b9182e7..c31f5a31 100644 --- a/src/hermes/commands/harvest/git.py +++ b/src/hermes/commands/harvest/git.py @@ -15,6 +15,7 @@ import shutil from hermes.model.context import HermesHarvestContext +from hermes.model.errors import HermesValidationError _log = logging.getLogger('harvest.git') @@ -274,15 +275,16 @@ def harvest_git(click_ctx: click.Context, ctx: HermesHarvestContext): p = subprocess.run([git_exe, "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True) if p.returncode: - raise RuntimeError(f"`git branch` command failed with code {p.returncode}: " - f"'{p.stderr.decode(SHELL_ENCODING)}'!") + raise HermesValidationError(f"`git branch` command failed with code {p.returncode}: " + f"'{p.stderr.decode(SHELL_ENCODING).rstrip()}'!") + git_branch = p.stdout.decode(SHELL_ENCODING).strip() # TODO: should we warn or error if the HEAD is detached? p = subprocess.run([git_exe, "log", f"--pretty={_GIT_SEP.join(_GIT_FORMAT)}"] + _GIT_ARGS, capture_output=True) if p.returncode: - raise RuntimeError(f"`git log` command failed with code {p.returncode}: " - f"'{p.stderr.decode(SHELL_ENCODING)}'!") + raise HermesValidationError(f"`git log` command failed with code {p.returncode}: " + f"'{p.stderr.decode(SHELL_ENCODING).rstrip()}'!") log = p.stdout.decode(SHELL_ENCODING).split('\n') for line in log: diff --git a/src/hermes/model/context.py b/src/hermes/model/context.py index 86a9469a..806bf53a 100644 --- a/src/hermes/model/context.py +++ b/src/hermes/model/context.py @@ -173,6 +173,9 @@ def __exit__(self, exc_type, exc_val, exc_tb): if exc_type is not None and issubclass(exc_type, HermesValidationError): exc = traceback.TracebackException(exc_type, exc_val, exc_tb) self._base.error(self._ep, exc) + self._log.warning("{}: {}".format( + exc_type.__name__, + ' '.join(str(x) for x in exc_val.args))) return True def update(self, _key: str, _value: t.Any, **kwargs: t.Any): From 01c0aabd7bc3ebd6c6f7c2d470db163ffbf41b4a Mon Sep 17 00:00:00 2001 From: jkelling Date: Thu, 12 Jan 2023 15:25:14 +0100 Subject: [PATCH 2/3] review changes: logging string format Co-authored-by: Michael Meinel --- src/hermes/model/context.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hermes/model/context.py b/src/hermes/model/context.py index 806bf53a..e8d5202d 100644 --- a/src/hermes/model/context.py +++ b/src/hermes/model/context.py @@ -173,9 +173,9 @@ def __exit__(self, exc_type, exc_val, exc_tb): if exc_type is not None and issubclass(exc_type, HermesValidationError): exc = traceback.TracebackException(exc_type, exc_val, exc_tb) self._base.error(self._ep, exc) - self._log.warning("{}: {}".format( - exc_type.__name__, - ' '.join(str(x) for x in exc_val.args))) + self._log.warning("%s: %s", + exc_type, + ' '.join(map(str, exc_val.args))) return True def update(self, _key: str, _value: t.Any, **kwargs: t.Any): From 7d4ab3d362eac4ff80e38fde330011400fe976ca Mon Sep 17 00:00:00 2001 From: Jeffrey Kelling Date: Thu, 12 Jan 2023 16:56:24 +0100 Subject: [PATCH 3/3] Fix flake8 visual indent --- src/hermes/model/context.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hermes/model/context.py b/src/hermes/model/context.py index e8d5202d..e10dbd9f 100644 --- a/src/hermes/model/context.py +++ b/src/hermes/model/context.py @@ -174,8 +174,8 @@ def __exit__(self, exc_type, exc_val, exc_tb): exc = traceback.TracebackException(exc_type, exc_val, exc_tb) self._base.error(self._ep, exc) self._log.warning("%s: %s", - exc_type, - ' '.join(map(str, exc_val.args))) + exc_type, + ' '.join(map(str, exc_val.args))) return True def update(self, _key: str, _value: t.Any, **kwargs: t.Any):