Skip to content

Commit

Permalink
Enhance the logging and reporting of run_command_safely #1257
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jun 18, 2024
1 parent 1cd9fef commit 6674a61
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ v34.6.2 (unreleased)
- Add support for fetching Git repository as Project input.
https://github.com/nexB/scancode.io/issues/921

- Enhance the logging and reporting of input fetch exceptions.
https://github.com/nexB/scancode.io/issues/1257

v34.6.1 (2024-06-07)
--------------------

Expand Down
1 change: 0 additions & 1 deletion scanpipe/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ def download_missing_inputs(self):
input_source.fetch()
except Exception as error:
traceback_str = traceback.format_exc()
self.log(str(error))
logger.error(traceback_str)
self.log(f"{input_source.download_url} could not be fetched.")
error_tracebacks.append((str(error), traceback_str))
Expand Down
15 changes: 11 additions & 4 deletions scanpipe/pipes/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,22 @@ def run_command_safely(command_args):
sure to sanitize and validate the input to prevent any malicious commands from
being executed.
As ``check`` is True, if the exit code is non-zero, it raises a CalledProcessError.
Raise a SubprocessError if the exit code was non-zero.
"""
result = subprocess.run( # nosec
completed_process = subprocess.run( # nosec
command_args,
capture_output=True,
text=True,
check=True,
)
return result.stdout

if completed_process.returncode:
error_msg = (
f'Error while executing cmd="{completed_process.args}": '
f'"{completed_process.stderr.strip()}"'
)
raise subprocess.SubprocessError(error_msg)

return completed_process.stdout


def get_request_session(uri):
Expand Down

0 comments on commit 6674a61

Please sign in to comment.