Skip to content

Commit

Permalink
Improve debug / timeout / onstop error output
Browse files Browse the repository at this point in the history
  • Loading branch information
deajan committed Sep 15, 2024
1 parent de7177d commit 4ee7113
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions command_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ def to_encoding(
except (ValueError, TypeError):
# What happens when str cannot be concatenated
logger.error("Output cannot be captured {}".format(process_output))
elif process_output is None:
# We deal with strings. Alter output string to avoid NoneType errors
process_output = ""
return process_output


Expand Down Expand Up @@ -1044,8 +1047,8 @@ def _monitor_process(
_stdout.write(output_stderr.encode(encoding, errors=errors))

logger.debug(
'Command "{}" returned with exit code "{}". Command output was:'.format(
command, exit_code
'Command "{}" returned with exit code "{}". Command output was:\n{}'.format(
command, exit_code, to_encoding(output_stdout, error_encoding, errors)
)
)
except subprocess.CalledProcessError as exc:
Expand Down Expand Up @@ -1093,7 +1096,7 @@ def _monitor_process(
exit_code, output_stdout = (-253, message)
except TimeoutExpired as exc:
message = 'Timeout {} seconds expired for command "{}" execution. Original output was: {}'.format(
timeout, command, exc.output
timeout, command, to_encoding(exc.output, error_encoding, errors)[-1000:]
)
if not silent:
logger.error(message)
Expand All @@ -1102,7 +1105,7 @@ def _monitor_process(
exit_code, output_stdout = (-254, message)
except StopOnInterrupt as exc:
message = "Command {} was stopped because stop_on function returned True. Original output was: {}".format(
command, to_encoding(exc.output, error_encoding, errors)
command, to_encoding(exc.output, error_encoding, errors)[-1000:]
)
if not silent:
logger.info(message)
Expand Down

0 comments on commit 4ee7113

Please sign in to comment.