comparison sat_frontends/jp/cmd_pubsub.py @ 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 864485605d12
comparison
equal deleted inserted replaced
3412:7b4ae3dbc041 3413:f4d417593e77
34 from functools import partial 34 from functools import partial
35 from sat.tools.common import data_format 35 from sat.tools.common import data_format
36 from sat.tools.common import uri 36 from sat.tools.common import uri
37 from sat.tools.common.ansi import ANSI as A 37 from sat.tools.common.ansi import ANSI as A
38 from sat_frontends.tools import jid, strings 38 from sat_frontends.tools import jid, strings
39 from sat_frontends.bridge.bridge_frontend import BridgeException
39 40
40 __commands__ = ["Pubsub"] 41 __commands__ = ["Pubsub"]
41 42
42 PUBSUB_TMP_DIR = "pubsub" 43 PUBSUB_TMP_DIR = "pubsub"
43 PUBSUB_SCHEMA_TMP_DIR = PUBSUB_TMP_DIR + "_schema" 44 PUBSUB_SCHEMA_TMP_DIR = PUBSUB_TMP_DIR + "_schema"
78 config_dict = await self.host.bridge.psNodeConfigurationGet( 79 config_dict = await self.host.bridge.psNodeConfigurationGet(
79 self.args.service, 80 self.args.service,
80 self.args.node, 81 self.args.node,
81 self.profile, 82 self.profile,
82 ) 83 )
83 except Exception as e: 84 except BridgeException as e:
84 self.disp(f"can't get node configuration: {e}", error=True) 85 if e.condition == 'item-not-found':
85 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 86 self.disp(
87 f"The node {self.args.node} doesn't exist on {self.args.service}",
88 error=True
89 )
90 self.host.quit(C.EXIT_NOT_FOUND)
91 else:
92 self.disp(f"can't get node configuration: {e}", error=True)
93 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
94 except Exception as e:
95 self.disp(f"Internal error: {e}", error=True)
96 self.host.quit(C.EXIT_INTERNAL_ERROR)
86 else: 97 else:
87 key_filter = (lambda k: True) if not self.args.keys else self.filterKey 98 key_filter = (lambda k: True) if not self.args.keys else self.filterKey
88 config_dict = { 99 config_dict = {
89 self.removePrefix(k): v for k, v in config_dict.items() if key_filter(k) 100 self.removePrefix(k): v for k, v in config_dict.items() if key_filter(k)
90 } 101 }
813 self.args.sub_id, 824 self.args.sub_id,
814 self.getPubsubExtra(), 825 self.getPubsubExtra(),
815 self.profile, 826 self.profile,
816 ) 827 )
817 ) 828 )
818 except Exception as e: 829 except BridgeException as e:
819 self.disp(f"can't get pubsub items: {e}", error=True) 830 if e.condition == 'item-not-found' or e.classname=="NotFound":
820 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 831 self.disp(
832 f"The node {self.args.node} doesn't exist on {self.args.service}",
833 error=True
834 )
835 self.host.quit(C.EXIT_NOT_FOUND)
836 else:
837 self.disp(f"can't get pubsub items: {e}", error=True)
838 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
839 except Exception as e:
840 self.disp(f"Internal error: {e}", error=True)
841 self.host.quit(C.EXIT_INTERNAL_ERROR)
821 else: 842 else:
822 await self.output(ps_result['items']) 843 await self.output(ps_result['items'])
823 self.host.quit(C.EXIT_OK) 844 self.host.quit(C.EXIT_OK)
824 845
825 846