comparison sat_frontends/jp/cmd_pubsub.py @ 3453:864485605d12

jp (pubsub/node/schema): handle not-found conditions properly
author Goffi <goffi@goffi.org>
date Fri, 11 Dec 2020 17:58:36 +0100
parents f4d417593e77
children 5901a7170528
comparison
equal deleted inserted replaced
3452:bb0225aaf4e6 3453:864485605d12
666 schema = await self.host.bridge.psSchemaGet( 666 schema = await self.host.bridge.psSchemaGet(
667 self.args.service, 667 self.args.service,
668 self.args.node, 668 self.args.node,
669 self.profile, 669 self.profile,
670 ) 670 )
671 except Exception as e: 671 except BridgeException as e:
672 self.disp(f"can't edit schema: {e}", error=True) 672 if e.condition == 'item-not-found' or e.classname=="NotFound":
673 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 673 schema = ""
674 else: 674 else:
675 await self.psSchemaGetCb(schema) 675 self.disp(f"can't edit schema: {e}", error=True)
676 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
677
678 await self.psSchemaGetCb(schema)
676 679
677 680
678 class NodeSchemaGet(base.CommandBase): 681 class NodeSchemaGet(base.CommandBase):
679 def __init__(self, host): 682 def __init__(self, host):
680 base.CommandBase.__init__( 683 base.CommandBase.__init__(
696 schema = await self.host.bridge.psSchemaGet( 699 schema = await self.host.bridge.psSchemaGet(
697 self.args.service, 700 self.args.service,
698 self.args.node, 701 self.args.node,
699 self.profile, 702 self.profile,
700 ) 703 )
701 except Exception as e: 704 except BridgeException as e:
702 self.disp(f"can't get schema: {e}", error=True) 705 if e.condition == 'item-not-found' or e.classname=="NotFound":
703 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 706 schema = None
704 else:
705 if schema:
706 await self.output(schema)
707 self.host.quit()
708 else: 707 else:
709 self.disp(_("no schema found"), 1) 708 self.disp(f"can't get schema: {e}", error=True)
710 self.host.quit(1) 709 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
710
711 if schema:
712 await self.output(schema)
713 self.host.quit()
714 else:
715 self.disp(_("no schema found"), 1)
716 self.host.quit(C.EXIT_NOT_FOUND)
711 717
712 718
713 class NodeSchema(base.CommandBase): 719 class NodeSchema(base.CommandBase):
714 subcommands = (NodeSchemaSet, NodeSchemaEdit, NodeSchemaGet) 720 subcommands = (NodeSchemaSet, NodeSchemaEdit, NodeSchemaGet)
715 721