Skip to content

Commit

Permalink
Audit: Better error message on subprocess error
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jun 15, 2024
1 parent 659faee commit 28f8f23
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion github_app_geo_project/module/audit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,14 @@ async def _process_snyk_dpkg(
else:
if pull_request is not None:
issue_check.set_title(key, f"{key} ([Pull request]({pull_request.html_url}))")

except subprocess.CalledProcessError as proc_error:
message = module_utils.ansi_proc_message(proc_error)
_LOGGER.exception("Audit %s process error", key)
return [f"Error while processing the audit {key}: {proc_error}"], False
except subprocess.TimeoutExpired as proc_error:
message = module_utils.ansi_proc_message(proc_error)
_LOGGER.exception("Audit %s process timeout error", key)
return [f"Error while processing the audit {key}: {proc_error}"], False
except Exception as exception: # pylint: disable=broad-except
_LOGGER.exception("Audit %s error", key)
return [f"Error while processing the audit {key}: {exception}"], False
Expand Down
4 changes: 3 additions & 1 deletion github_app_geo_project/module/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ def from_process(
return AnsiProcessMessage(cast(list[str], proc.args), proc.returncode, proc.stdout, proc.stderr)


def ansi_proc_message(proc: subprocess.CompletedProcess[str] | subprocess.CalledProcessError) -> Message:
def ansi_proc_message(
proc: subprocess.CompletedProcess[str] | subprocess.CalledProcessError | subprocess.TimeoutExpired,
) -> Message:
"""
Process the output of a subprocess for the dashboard (markdown)/HTML.
Expand Down
2 changes: 1 addition & 1 deletion github_app_geo_project/scripts/process_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ async def _process_job(
finally:
root_logger.removeHandler(handler)
raise
except subprocess.CalledProcessError as proc_error:
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as proc_error:
job.status = models.JobStatus.ERROR
job.finished_at = datetime.datetime.now(tz=datetime.timezone.utc)
message = module_utils.ansi_proc_message(proc_error)
Expand Down

0 comments on commit 28f8f23

Please sign in to comment.