[GHF] More verbose failures messages (#71941)

Summary:
Modify _check_output to capture `CalledProcessError` and add
stdout/stderr to the failure message
Also record github actions run id in the failure message (calculated based on `${{ github.run_id}}`)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/71941

Reviewed By: seemethere

Differential Revision: D33829633

Pulled By: malfet

fbshipit-source-id: 060b2856ca6c71574075effa72b982f9e1d64e6e
(cherry picked from commit a9ad7df9b540f9ab14524a644cab5e06225debe4)
This commit is contained in:
Nikita Shulga
2022-01-27 15:45:40 -08:00
committed by PyTorch MergeBot
parent c85965600c
commit 3b9f2e2cca
4 changed files with 24 additions and 4 deletions

View File

@ -30,8 +30,18 @@ def fuzzy_list_to_dict(items: List[Tuple[str, str]]) -> Dict[str, List[str]]:
def _check_output(items: List[str], encoding: str = "utf-8") -> str:
from subprocess import check_output
return check_output(items).decode(encoding)
from subprocess import check_output, CalledProcessError
try:
return check_output(items).decode(encoding)
except CalledProcessError as e:
msg = f"Command `{' '.join(e.cmd)}` returned non-zero exit code {e.returncode}"
stdout = e.stdout.decode(encoding) if e.stdout is not None else ""
stderr = e.stderr.decode(encoding) if e.stderr is not None else ""
if len(stderr) == 0:
msg += f"\n{stdout}"
else:
msg += f"\nstdout:\n{stdout}\nstderr:\n{stderr}"
raise RuntimeError(msg) from e
class GitCommit: