From fc2e8094a63588242ffa11014e3ffa585cbcb556 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Tue, 18 Oct 2022 11:50:53 +0200 Subject: [PATCH] fix --- setup.cfg | 2 +- src/de/p1st/exec_notify/execNotify.py | 5 ++++- src/de/p1st/exec_notify/lib/exec.py | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7bf6d63..8d11f3b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ [metadata] name = de.p1st.exec_notify -version = 0.1.9 +version = 0.1.10 author = Daniel Langbein author_email = daniel@systemli.org description = mail notification if command fails diff --git a/src/de/p1st/exec_notify/execNotify.py b/src/de/p1st/exec_notify/execNotify.py index b96c1de..ea62cb5 100755 --- a/src/de/p1st/exec_notify/execNotify.py +++ b/src/de/p1st/exec_notify/execNotify.py @@ -32,7 +32,10 @@ def executeCommand(command: List[str]) -> int: :return: exit code of executed command """ - exitCode, stdout, stderr = exec.execute(command) + try: + exitCode, stdout, stderr = exec.execute(command) + except Exception as e: + exitCode, stdout, stderr = 1, '', 'Caught subprocess exception: ' + str(e) prefix = '┃ ' BODY = f'┏{"━" * 19}\n' \ diff --git a/src/de/p1st/exec_notify/lib/exec.py b/src/de/p1st/exec_notify/lib/exec.py index 87b903d..a7af4d1 100644 --- a/src/de/p1st/exec_notify/lib/exec.py +++ b/src/de/p1st/exec_notify/lib/exec.py @@ -9,8 +9,9 @@ def execute(command: List[str]): Runs the given command in a subprocess and passes stdin (if given) to that process. Waits for command to complete. - :param command: A command to executed as list of words, e.g. ['echo', 'Hello world!'] + :param command: A command to executed as list of words, e.g. `['echo', 'Hello world!']` :return: (exit_code, stdout, stderr) + :raises Exception: Might throw an exception.E.g. FileNotFoundError if the executable (first element of `command`) does not exist. """ if sys.version_info.major == 3 and sys.version_info.minor < 7: