# HG changeset patch # User Goffi # Date 1607081576 -3600 # Node ID df775db4c49bc5a01b36c78c4327cebbe0a4b10f # Parent c84c54c6b046d3eb2335b7163b2aab5a317627b3 jp (account): better exit code handling diff -r c84c54c6b046 -r df775db4c49b sat_frontends/jp/cmd_account.py --- a/sat_frontends/jp/cmd_account.py Fri Dec 04 12:32:05 2020 +0100 +++ b/sat_frontends/jp/cmd_account.py Fri Dec 04 12:32:56 2020 +0100 @@ -20,13 +20,15 @@ """This module permits to manage XMPP accounts using in-band registration (XEP-0077)""" from sat_frontends.jp.constants import Const as C +from sat_frontends.bridge.bridge_frontend import BridgeException from sat.core.log import getLogger - -log = getLogger(__name__) from sat.core.i18n import _ from sat_frontends.jp import base from sat_frontends.tools import jid + +log = getLogger(__name__) + __commands__ = ["Account"] @@ -83,11 +85,22 @@ self.args.host, self.args.port, ) + + except BridgeException as e: + if e.condition == 'conflict': + self.disp( + f"The account {self.args.jid} already exists", + error=True + ) + self.host.quit(C.EXIT_CONFLICT) + else: + self.disp( + f"can't create account on {self.args.host or 'localhost'!r} with jid " + f"{self.args.jid!r} using In-Band Registration: {e}", error=True) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) except Exception as e: - self.disp( - f"can't create account on {self.args.host or 'localhost'!r} with jid " - f"{self.args.jid!r} using In-Band Registration: {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) self.disp(_("XMPP account created"), 1) @@ -102,13 +115,23 @@ self.args.password, "", ) + except BridgeException as e: + if e.condition == 'conflict': + self.disp( + f"The profile {self.args.profile} already exists", + error=True + ) + self.host.quit(C.EXIT_CONFLICT) + else: + self.disp( + _(f"Can't create profile {self.args.profile} to associate with jid " + f"{self.args.jid}: {e}"), + error=True, + ) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) except Exception as e: - self.disp( - _(f"Can't create profile {self.args.profile} to associate with jid " - f"{self.args.jid}: {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) self.disp(_("profile created"), 1) try: