mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 13:08:31 +02:00
Format code a bit nicer
This commit is contained in:
parent
7ac104a60d
commit
b0f437f345
2 changed files with 22 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
# Copyright (C) 2012-2021 jrnl contributors
|
# Copyright (C) 2012-2021 jrnl contributors
|
||||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
|
||||||
class UserAbort(Exception):
|
class UserAbort(Exception):
|
||||||
|
@ -17,14 +18,19 @@ class JrnlError(Exception):
|
||||||
|
|
||||||
def __init__(self, error_type, **kwargs):
|
def __init__(self, error_type, **kwargs):
|
||||||
self.error_type = error_type
|
self.error_type = error_type
|
||||||
self.message = self.get_error_message(**kwargs)
|
self.message = self._get_error_message(**kwargs)
|
||||||
|
|
||||||
def get_error_message(self, **kwargs):
|
|
||||||
|
|
||||||
|
def _get_error_message(self, **kwargs):
|
||||||
error_messages = {
|
error_messages = {
|
||||||
"ConfigDirectoryIsFile": "The path to your jrnl configuration directory is a file, not a directory:\n"
|
"ConfigDirectoryIsFile": textwrap.dedent(
|
||||||
+ "{config_directory_path}\n"
|
"""
|
||||||
+ "Removing this file will allow jrnl to save its configuration."
|
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)
|
return error_messages[self.error_type].format(**kwargs)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import textwrap
|
||||||
|
|
||||||
from jrnl.exception import JrnlError
|
from jrnl.exception import JrnlError
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,8 +8,12 @@ def test_config_directory_exception_message():
|
||||||
"ConfigDirectoryIsFile", config_directory_path="/config/directory/path"
|
"ConfigDirectoryIsFile", config_directory_path="/config/directory/path"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert ex.message == (
|
assert ex.message == textwrap.dedent(
|
||||||
"The path to your jrnl configuration directory is a file, not a directory:\n"
|
"""
|
||||||
+ "/config/directory/path\n"
|
The path to your jrnl configuration directory is a file, not a directory:
|
||||||
+ "Removing this file will allow jrnl to save its configuration."
|
|
||||||
|
/config/directory/path
|
||||||
|
|
||||||
|
Removing this file will allow jrnl to save its configuration.
|
||||||
|
"""
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue