diff --git a/github_app_geo_project/module/audit/utils.py b/github_app_geo_project/module/audit/utils.py index f0ecf03e712..04d2b7c0b61 100644 --- a/github_app_geo_project/module/audit/utils.py +++ b/github_app_geo_project/module/audit/utils.py @@ -296,7 +296,9 @@ async def _snyk_test( message.title = "Snyk test JSON output" _LOGGER.debug(message) else: - _LOGGER.error("Snyk test JSON returned nothing on project %s branch %s", os.getcwd(), branch) + _LOGGER.error( + "Snyk test JSON returned nothing on project %s branch %s", module_utils.get_cwd(), branch + ) test_json = json.loads(test_json_str) if test_json_str else [] diff --git a/github_app_geo_project/module/utils.py b/github_app_geo_project/module/utils.py index 74a5a1d62fc..d6322e66294 100644 --- a/github_app_geo_project/module/utils.py +++ b/github_app_geo_project/module/utils.py @@ -459,6 +459,18 @@ def ansi_proc_message( return AnsiProcessMessage.from_process(proc) +def get_cwd() -> str | None: + """ + Get the current working directory. + + Did not raise an exception if it does not exist, return None instead. + """ + try: + return os.getcwd() + except FileNotFoundError: + return None + + async def run_timeout( command: list[str], env: dict[str, str] | None, @@ -490,7 +502,7 @@ async def run_timeout( async with asyncio.timeout(timeout): async_proc = await asyncio.create_subprocess_exec( *command, - cwd=cwd or os.getcwd(), + cwd=cwd or get_cwd(), env=env, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,