Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user-friendly message when missing importer #1959

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion jrnl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,17 @@ def postconfig_import(args: argparse.Namespace, config: dict, **_) -> int:
journal = open_journal(args.journal_name, config)

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

Expand Down
5 changes: 5 additions & 0 deletions jrnl/messages/MsgText.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ def __str__(self) -> str:
{count} imported to {journal_name} journal
"""

ImporterNotFound = """
No importer found for file type '{format}'.
'{format}' is likely to be an export-only format.
"""

# --- Color --- #
InvalidColor = "{key} set to invalid color: {color}"

Expand Down