Skip to content

Commit 4ee7113

Browse files
committed
Improve debug / timeout / onstop error output
1 parent de7177d commit 4ee7113

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

command_runner/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ def to_encoding(
337337
except (ValueError, TypeError):
338338
# What happens when str cannot be concatenated
339339
logger.error("Output cannot be captured {}".format(process_output))
340+
elif process_output is None:
341+
# We deal with strings. Alter output string to avoid NoneType errors
342+
process_output = ""
340343
return process_output
341344

342345

@@ -1044,8 +1047,8 @@ def _monitor_process(
10441047
_stdout.write(output_stderr.encode(encoding, errors=errors))
10451048

10461049
logger.debug(
1047-
'Command "{}" returned with exit code "{}". Command output was:'.format(
1048-
command, exit_code
1050+
'Command "{}" returned with exit code "{}". Command output was:\n{}'.format(
1051+
command, exit_code, to_encoding(output_stdout, error_encoding, errors)
10491052
)
10501053
)
10511054
except subprocess.CalledProcessError as exc:
@@ -1093,7 +1096,7 @@ def _monitor_process(
10931096
exit_code, output_stdout = (-253, message)
10941097
except TimeoutExpired as exc:
10951098
message = 'Timeout {} seconds expired for command "{}" execution. Original output was: {}'.format(
1096-
timeout, command, exc.output
1099+
timeout, command, to_encoding(exc.output, error_encoding, errors)[-1000:]
10971100
)
10981101
if not silent:
10991102
logger.error(message)
@@ -1102,7 +1105,7 @@ def _monitor_process(
11021105
exit_code, output_stdout = (-254, message)
11031106
except StopOnInterrupt as exc:
11041107
message = "Command {} was stopped because stop_on function returned True. Original output was: {}".format(
1105-
command, to_encoding(exc.output, error_encoding, errors)
1108+
command, to_encoding(exc.output, error_encoding, errors)[-1000:]
11061109
)
11071110
if not silent:
11081111
logger.info(message)

0 commit comments

Comments
 (0)