diff --git a/jrnl/exception.py b/jrnl/exception.py index 0ffc27fb..3ef7e5b4 100644 --- a/jrnl/exception.py +++ b/jrnl/exception.py @@ -1,5 +1,6 @@ # Copyright (C) 2012-2021 jrnl contributors # License: https://www.gnu.org/licenses/gpl-3.0.html +import textwrap class UserAbort(Exception): @@ -17,14 +18,19 @@ class JrnlError(Exception): def __init__(self, error_type, **kwargs): self.error_type = error_type - self.message = self.get_error_message(**kwargs) - - def get_error_message(self, **kwargs): + self.message = self._get_error_message(**kwargs) + def _get_error_message(self, **kwargs): error_messages = { - "ConfigDirectoryIsFile": "The path to your jrnl configuration directory is a file, not a directory:\n" - + "{config_directory_path}\n" - + "Removing this file will allow jrnl to save its configuration." + "ConfigDirectoryIsFile": textwrap.dedent( + """ + 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. + """ + ) } return error_messages[self.error_type].format(**kwargs) diff --git a/tests/test_exception.py b/tests/test_exception.py index a369ac08..85eb77e9 100644 --- a/tests/test_exception.py +++ b/tests/test_exception.py @@ -1,3 +1,5 @@ +import textwrap + from jrnl.exception import JrnlError @@ -6,8 +8,12 @@ def test_config_directory_exception_message(): "ConfigDirectoryIsFile", config_directory_path="/config/directory/path" ) - assert ex.message == ( - "The path to your jrnl configuration directory is a file, not a directory:\n" - + "/config/directory/path\n" - + "Removing this file will allow jrnl to save its configuration." + assert ex.message == textwrap.dedent( + """ + 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. + """ )