2022-08-24 15:01:07 +00:00
|
|
|
import traceback
|
|
|
|
|
2022-08-24 11:41:11 +00:00
|
|
|
from shell.interfaces import CommandResult
|
|
|
|
|
2022-08-24 15:01:07 +00:00
|
|
|
|
|
|
|
def format_error_details(error: Exception) -> str:
|
2022-08-24 11:41:11 +00:00
|
|
|
"""
|
|
|
|
Converts specified exception instance into a string that includes error message
|
|
|
|
and full stack trace.
|
|
|
|
|
|
|
|
:param Exception error: exception to convert.
|
|
|
|
:return: string containing exception details.
|
|
|
|
"""
|
|
|
|
detail_lines = traceback.format_exception(
|
2022-08-24 15:01:07 +00:00
|
|
|
etype=type(error),
|
|
|
|
value=error,
|
2022-08-24 11:41:11 +00:00
|
|
|
tb=error.__traceback__,
|
2022-08-24 15:01:07 +00:00
|
|
|
)
|
2022-08-24 11:41:11 +00:00
|
|
|
return "".join(detail_lines)
|
|
|
|
|
|
|
|
|
|
|
|
def get_output_lines(result: CommandResult) -> list[str]:
|
|
|
|
"""
|
|
|
|
Converts output of specified command result into separate lines trimmed from whitespaces.
|
|
|
|
Empty lines are excluded.
|
|
|
|
|
|
|
|
:param CommandResult result: result which output should be converted.
|
|
|
|
:return: list of lines extracted from the output.
|
|
|
|
"""
|
|
|
|
return [line.strip() for line in result.stdout.split("\n") if line.strip()]
|