replace sys.exit call with new exception handling

This commit is contained in:
Jonathan Wren 2022-03-12 14:42:04 -08:00
parent 6a4915c393
commit c5fc211ae9
3 changed files with 6 additions and 4 deletions

View file

@ -197,9 +197,9 @@ def get_journal_name(args, config):
args.text = args.text[1:] args.text = args.text[1:]
if args.journal_name not in config["journals"]: if args.journal_name not in config["journals"]:
print("No default journal configured.", file=sys.stderr) raise JrnlException(
print(list_journals(config), file=sys.stderr) Message(MsgText.NoDefaultJournal, MsgType.ERROR, { "journals": list_journals(config)}),
sys.exit(1) )
logging.debug("Using journal name: %s", args.journal_name) logging.debug("Using journal name: %s", args.journal_name)
return args return args

View file

@ -67,6 +67,8 @@ class MsgText(Enum):
{template} {template}
""" """
NoDefaultJournal = "No default journal configured\n{journals}"
# --- Journal status ---# # --- Journal status ---#
JournalNotSaved = "Entry NOT saved to journal" JournalNotSaved = "Entry NOT saved to journal"

View file

@ -30,7 +30,7 @@ def list_journals(configuration):
from . import config from . import config
"""List the journals specified in the configuration file""" """List the journals specified in the configuration file"""
result = f"Journals defined in {config.get_config_path()}\n" result = f"Journals defined in config ({config.get_config_path()})\n"
ml = min(max(len(k) for k in configuration["journals"]), 20) ml = min(max(len(k) for k in configuration["journals"]), 20)
for journal, cfg in configuration["journals"].items(): for journal, cfg in configuration["journals"].items():
result += " * {:{}} -> {}\n".format( result += " * {:{}} -> {}\n".format(