From 7242224e43b8e6049e7bf1995d942630224a9a08 Mon Sep 17 00:00:00 2001 From: Sasa Bojanic <48201593+sale3@users.noreply.github.com> Date: Tue, 24 Sep 2024 23:52:13 +0200 Subject: [PATCH] fix: raise original error message alongside generic GitError message (#539) --- taf/exceptions.py | 5 +++-- taf/git.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/taf/exceptions.py b/taf/exceptions.py index 1b97c40e..584750e0 100644 --- a/taf/exceptions.py +++ b/taf/exceptions.py @@ -1,4 +1,5 @@ from typing import List, Optional, Any, Tuple +import subprocess class TAFError(Exception): @@ -28,14 +29,14 @@ def __init__( self, repo: Any, command: Optional[str] = None, - error: Optional[Exception] = None, + error: Optional[subprocess.CalledProcessError] = None, message: Optional[str] = None, ): if message is None: if command is not None: message = f"error occurred while executing {command}" if error is not None: - message = f"{message}:\n{str(error)}" + message = f"{message}:\n{str(error.stdout)}" elif error is not None: message = str(error) else: diff --git a/taf/git.py b/taf/git.py index 644aef66..24c5b7c3 100644 --- a/taf/git.py +++ b/taf/git.py @@ -872,7 +872,7 @@ def commit(self, message: str) -> str: return self._git("rev-parse HEAD") except subprocess.CalledProcessError as e: raise GitError( - repo=self, message=f"could not commit changes due to:\n{e}" + repo=self, message=f"could not commit changes due to:\n{e}", error=e ) else: raise NothingToCommitError(repo=self, message="No changes to commit")