Mercurial > libervia-backend
changeset 3413:f4d417593e77
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 12 Nov 2020 14:53:16 +0100 |
parents | 7b4ae3dbc041 |
children | ffe7a6d6018a |
files | sat_frontends/jp/cmd_pubsub.py |
diffstat | 1 files changed, 25 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_pubsub.py Thu Nov 12 14:53:16 2020 +0100 +++ b/sat_frontends/jp/cmd_pubsub.py Thu Nov 12 14:53:16 2020 +0100 @@ -36,6 +36,7 @@ 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 @@ 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 @@ 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)