Skip to content

Commit

Permalink
Slightly improve logged warning message
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrice Normandin <normandf@mila.quebec>
  • Loading branch information
lebrice committed Apr 15, 2024
1 parent 0ff91e3 commit 1049e1b
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions milatools/utils/local_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ async def run_async(
subprocess.CalledProcessError
If an error occurs when running the command and `warn` is `False`.
"""
command_with_input = program_and_args + ((input,) if input else ())

logger.debug(f"Calling `asyncio.create_subprocess_exec` with {program_and_args=}")
proc = await asyncio.create_subprocess_exec(
Expand All @@ -195,17 +194,19 @@ async def run_async(
start_new_session=False,
)
if input:
# TODO: Getting a bug when sending 'echo $SCRATCH'!
logger.debug(f"Sending {input=!r} to the subprocess' stdin.")

stdout, stderr = await proc.communicate(input.encode() if input else None)

assert proc.returncode is not None
if proc.returncode != 0:
logger.debug(
f"[{command_with_input!r}"
message = (
f"{program_and_args!r}"
+ (f" with input {input!r}" if input else "")
+ f" exited with {proc.returncode}]"
+ f" exited with {proc.returncode}"
+ (f": {stderr}" if stderr else "")
)
logger.debug(message)
if not warn:
if stderr:
logger.error(stderr)
Expand All @@ -216,11 +217,7 @@ async def run_async(
stderr=stderr,
)
if hide is not True: # don't warn if hide is True.
logger.warning(
RuntimeWarning(
f"Command {program_and_args!r} returned non-zero exit code {proc.returncode}: {stderr}"
)
)
logger.warning(RuntimeWarning(message))
result = subprocess.CompletedProcess(
args=program_and_args,
returncode=proc.returncode,
Expand Down

0 comments on commit 1049e1b

Please sign in to comment.