Skip to content

Commit 4d389ac

Browse files
authored
fix logging of stdout und stderr (#2661)
* fix logging of stdout und stderr * fix * simplify
1 parent 364df0b commit 4d389ac

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

packages/helpermodules/command.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -963,16 +963,17 @@ def __enter__(self):
963963
return None
964964

965965
def __exit__(self, exception_type, exception, exception_traceback) -> bool:
966-
if isinstance(exception, Exception):
966+
if isinstance(exception, subprocess.CalledProcessError):
967967
pub_user_message(self.payload, self.connection_id,
968-
f'Es ist ein interner Fehler aufgetreten: {exception}', MessageType.ERROR)
969-
log.error({traceback.format_exc()})
968+
(f'Fehler-Status: {exception.returncode}<br />Meldung: '
969+
f'{exception.stderr if exception.stderr else ""} '
970+
f'{exception.output if exception.output else ""}'),
971+
MessageType.ERROR)
970972
return True
971-
elif isinstance(exception, subprocess.CalledProcessError):
972-
log.debug(exception.stdout)
973+
elif isinstance(exception, Exception):
973974
pub_user_message(self.payload, self.connection_id,
974-
f'Fehler-Status: {exception.returncode}<br />Meldung: {exception.stderr}',
975-
MessageType.ERROR)
975+
f'Es ist ein interner Fehler aufgetreten: {exception}', MessageType.ERROR)
976+
log.error({traceback.format_exc()})
976977
return True
977978
else:
978979
return False

packages/helpermodules/utils/run_command.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def run_command(command, process_exception: bool = False):
3030
return result.stdout
3131
except subprocess.CalledProcessError as e:
3232
if process_exception:
33-
log.debug(e.stdout)
34-
log.exception(e.stderr)
33+
if e.output is not None:
34+
log.exception(e.output)
35+
if e.stderr is not None:
36+
log.exception(e.stderr)
3537
else:
3638
raise e

0 commit comments

Comments
 (0)