diff options
author | Toke Høiland-Jørgensen <toke@toke.dk> | 2021-01-03 03:26:52 +0300 |
---|---|---|
committer | Toke Høiland-Jørgensen <toke@toke.dk> | 2021-01-03 03:26:52 +0300 |
commit | b295ee1be1f6ed0ee847c274637c5638ed88563f (patch) | |
tree | ece4259a1fd0211a0fd2cf56f617c01492933378 | |
parent | 847b95dfebfa9cee0533138e77915c5a49a62c7b (diff) |
Better error message on failed update runner
The feed update runner can fail for various reasons, most notably
connection errors when receiving the feed URL. Currently, this will result
in a Python exception being propagated to the main runner loop and will
result in a not-so-useful traceback without any indication on what the
error runner actually said when it failed.
To fix this, catch the CalledProcessError directly in the updater and turn
it into a meaningful error message with the command output instead of a
Python traceback. This gives both a more meaningful error message, and a
cleaner output without Python tracebacks.
Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
-rw-r--r-- | nextcloud_news_updater/api/cli.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/nextcloud_news_updater/api/cli.py b/nextcloud_news_updater/api/cli.py index cc68dfd..4b2b428 100644 --- a/nextcloud_news_updater/api/cli.py +++ b/nextcloud_news_updater/api/cli.py @@ -1,4 +1,4 @@ -from subprocess import check_output +from subprocess import check_output, CalledProcessError, STDOUT from typing import List, Any from nextcloud_news_updater.api.api import Api, Feed @@ -9,7 +9,7 @@ from nextcloud_news_updater.config import Config class Cli: def run(self, commands: List[str]) -> bytes: - return check_output(commands) + return check_output(commands, stderr=STDOUT) class CliApi(Api): @@ -73,12 +73,20 @@ class CliUpdateThread(UpdateThread): self.cli = cli self.api = api + def run_command(self, command: List[str]) -> None: + self.logger.info('Running update command: %s' % ' '.join(command)) + try: + self.cli.run(command) + except CalledProcessError as e: + self.logger.error("Command '%s' returned %d with output: '%s'" % + (' '. join(command), + e.returncode, + e.output.decode().strip())) + def update_feed(self, feed: Feed) -> None: command = self.api.update_feed_command + [str(feed.feed_id), feed.user_id] - self.logger.info('Running update command: %s' % ' '.join(command)) - self.cli.run(command) - + self.run_command(command) class CliUpdateThreadV15(CliUpdateThread): """Cli Updater for Nextcloud News v15+""" @@ -86,9 +94,7 @@ class CliUpdateThreadV15(CliUpdateThread): def update_feed(self, feed: Feed) -> None: command = self.api.update_feed_command + [feed.user_id, str(feed.feed_id)] - self.logger.info('Running update command: %s' % ' '.join(command)) - self.cli.run(command) - + self.run_command(command) class CliUpdater(Updater): def __init__(self, config: Config, logger: Logger, api: CliApi, |