Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit: Better error message on subprocess error #370

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 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,10 @@ 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, subprocess.TimeoutExpired) 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 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
8 changes: 6 additions & 2 deletions github_app_geo_project/module/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,17 @@ def to_markdown(self, summary: bool = False) -> str:

@staticmethod
def from_process(
proc: subprocess.CompletedProcess[str] | subprocess.CalledProcessError,
proc: subprocess.CompletedProcess[str] | subprocess.CalledProcessError | subprocess.TimeoutExpired,
) -> "AnsiProcessMessage":
"""Create a process message from a subprocess."""
if isinstance(proc, subprocess.TimeoutExpired):
return AnsiProcessMessage(cast(list[str], proc.args), None, proc.output, cast(str, proc.stderr))
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