From df6428c14c1e2fd78f60357e5d8415bced90fcb6 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 12 Nov 2020 14:53:16 +0100 Subject: [PATCH] jp (pubsub/node/info, pubsub/get): better exit code: the correct exit code is now returned in case of NOT_FOUND or bridge exception. If the exception is not a bridge exception, an internal error exit code is used. --- sat_frontends/jp/cmd_pubsub.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/sat_frontends/jp/cmd_pubsub.py b/sat_frontends/jp/cmd_pubsub.py index de8c6c04..12165727 100644 --- a/sat_frontends/jp/cmd_pubsub.py +++ b/sat_frontends/jp/cmd_pubsub.py @@ -36,6 +36,7 @@ from sat.tools.common import data_format from sat.tools.common import uri from sat.tools.common.ansi import ANSI as A from sat_frontends.tools import jid, strings +from sat_frontends.bridge.bridge_frontend import BridgeException __commands__ = ["Pubsub"] @@ -80,9 +81,19 @@ class NodeInfo(base.CommandBase): self.args.node, self.profile, ) + except BridgeException as e: + if e.condition == 'item-not-found': + self.disp( + f"The node {self.args.node} doesn't exist on {self.args.service}", + error=True + ) + self.host.quit(C.EXIT_NOT_FOUND) + else: + self.disp(f"can't get node configuration: {e}", error=True) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) except Exception as e: - self.disp(f"can't get node configuration: {e}", error=True) - self.host.quit(C.EXIT_BRIDGE_ERRBACK) + self.disp(f"Internal error: {e}", error=True) + self.host.quit(C.EXIT_INTERNAL_ERROR) else: key_filter = (lambda k: True) if not self.args.keys else self.filterKey config_dict = { @@ -815,9 +826,19 @@ class Get(base.CommandBase): self.profile, ) ) + except BridgeException as e: + if e.condition == 'item-not-found' or e.classname=="NotFound": + self.disp( + f"The node {self.args.node} doesn't exist on {self.args.service}", + error=True + ) + self.host.quit(C.EXIT_NOT_FOUND) + else: + self.disp(f"can't get pubsub items: {e}", error=True) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) except Exception as e: - self.disp(f"can't get pubsub items: {e}", error=True) - self.host.quit(C.EXIT_BRIDGE_ERRBACK) + self.disp(f"Internal error: {e}", error=True) + self.host.quit(C.EXIT_INTERNAL_ERROR) else: await self.output(ps_result['items']) self.host.quit(C.EXIT_OK)