mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
* Update and modularize exception handling cc #1024 #1141 - Stack traces are no longer shown to users unless the --debug flag is being used - Errors, warnings, and other messages contain color as needed - Converted error messages to Enum - Adds print_msg function to centralize output (this should replace all other output in other modules) Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
79 lines
2.2 KiB
Python
79 lines
2.2 KiB
Python
from enum import Enum
|
|
from typing import NamedTuple
|
|
from typing import Mapping
|
|
|
|
|
|
class _MsgColor(NamedTuple):
|
|
# This is a colorama color, and colorama doesn't support enums or type hints
|
|
# see: https://github.com/tartley/colorama/issues/91
|
|
color: str
|
|
|
|
|
|
class MsgType(Enum):
|
|
TITLE = _MsgColor("cyan")
|
|
NORMAL = _MsgColor("white")
|
|
WARNING = _MsgColor("yellow")
|
|
ERROR = _MsgColor("red")
|
|
|
|
@property
|
|
def color(self) -> _MsgColor:
|
|
return self.value.color
|
|
|
|
|
|
class MsgText(Enum):
|
|
def __str__(self) -> str:
|
|
return self.value
|
|
|
|
# --- Exceptions ---#
|
|
UncaughtException = """
|
|
ERROR
|
|
{exception}
|
|
|
|
This is probably a bug. Please file an issue at:
|
|
https://github.com/jrnl-org/jrnl/issues/new/choose
|
|
"""
|
|
|
|
ConfigDirectoryIsFile = """
|
|
The path to your jrnl configuration directory is a file, not a directory:
|
|
|
|
{config_directory_path}
|
|
|
|
Removing this file will allow jrnl to save its configuration.
|
|
"""
|
|
|
|
LineWrapTooSmallForDateFormat = """
|
|
The provided linewrap value of {config_linewrap} is too small by
|
|
{columns} columns to display the timestamps in the configured time
|
|
format for journal {journal}.
|
|
|
|
You can avoid this error by specifying a linewrap value that is larger
|
|
by at least {columns} in the configuration file or by using
|
|
--config-override at the command line
|
|
"""
|
|
|
|
CannotEncryptJournalType = """
|
|
The journal {journal_name} can't be encrypted because it is a
|
|
{journal_type} journal.
|
|
|
|
To encrypt it, create a new journal referencing a file, export
|
|
this journal to the new journal, then encrypt the new journal.
|
|
"""
|
|
|
|
KeyboardInterruptMsg = "Aborted by user"
|
|
|
|
# --- Journal status ---#
|
|
JournalNotSaved = "Entry NOT saved to journal"
|
|
|
|
# --- Editor ---#
|
|
WritingEntryStart = """
|
|
Writing Entry
|
|
To finish writing, press {how_to_quit} on a blank line.
|
|
"""
|
|
HowToQuitWindows = "Ctrl+z and then Enter"
|
|
HowToQuitLinux = "Ctrl+d"
|
|
|
|
|
|
class Message(NamedTuple):
|
|
text: MsgText
|
|
type: MsgType = MsgType.NORMAL
|
|
params: Mapping = {}
|