Add user-friendly message when missing importer

This commit is contained in:
edoardob90 2024-11-17 13:57:42 +01:00
parent eb5fe6fef1
commit 1609ea6bf8
2 changed files with 16 additions and 1 deletions

View file

@ -76,7 +76,17 @@ def postconfig_import(args: argparse.Namespace, config: dict, **_) -> int:
journal = open_journal(args.journal_name, config) journal = open_journal(args.journal_name, config)
format = args.export if args.export else "jrnl" format = args.export if args.export else "jrnl"
get_importer(format).import_(journal, args.filename)
if (importer := get_importer(format)) is None:
raise JrnlException(
Message(
MsgText.ImporterNotFound,
MsgStyle.ERROR,
{"format": format},
)
)
importer.import_(journal, args.filename)
return 0 return 0

View file

@ -266,6 +266,11 @@ class MsgText(Enum):
{count} imported to {journal_name} journal {count} imported to {journal_name} journal
""" """
ImporterNotFound = """
No importer found for file type '{format}'.
'{format}' is likely to be an export-only format.
"""
# --- Color --- # # --- Color --- #
InvalidColor = "{key} set to invalid color: {color}" InvalidColor = "{key} set to invalid color: {color}"