diff --git a/meltano/edk/process.py b/meltano/edk/process.py index 631070b..934a019 100644 --- a/meltano/edk/process.py +++ b/meltano/edk/process.py @@ -62,6 +62,7 @@ def run( stdout: None | int | t.IO = subprocess.PIPE, stderr: None | int | t.IO = subprocess.PIPE, text: bool = True, + raise_error: bool = True, **kwargs: t.Any, ) -> subprocess.CompletedProcess: """Run a subprocess. Simple wrapper around subprocess.run. @@ -77,14 +78,16 @@ def run( to override these you're likely better served using `subprocess.run` directly. Lastly note that this method is blocking AND `subprocess.run` is called with - `check=True`. This means that if the subprocess fails a `CalledProcessError` - will be raised. + `check=True` and `raise_error=True`. This means that if the subprocess + fails a `CalledProcessError` will be raised. Args: *args: The arguments to pass to the subprocess. stdout: The stdout stream to use. stderr: The stderr stream to use. text: If true, decode stdin, stdout and stderr using the system default. + raise_error: If true, decode stdin, stdout and stderr using the + system default. **kwargs: Additional keyword arguments to pass to subprocess.run. Returns: @@ -167,6 +170,7 @@ async def _exec( def run_and_log( self, sub_command: str | None = None, + raise_error: bool = True, *args: ExecArg, ) -> None: """Run a subprocess and stream the output to the logger. @@ -176,13 +180,23 @@ def run_and_log( Args: sub_command: The subcommand to run. + raise_error: If True (default), raises a CalledProcessError if + the subprocess fails. *args: The arguments to pass to the subprocess. Raises: CalledProcessError: If the subprocess failed. """ result = asyncio.run(self._exec(sub_command, *args)) - if result.returncode: + if result.returncode and raise_error: raise subprocess.CalledProcessError( result.returncode, cmd=self.bin, stderr=None ) + elif result.returncode and not raise_error: + log_subprocess_error( + self.bin, + subprocess.CalledProcessError( + result.returncode, cmd=self.bin, stderr=None + ), + "Error running subprocess", + )