Add exception and handling for when configuration directory is actually a file

This commit is contained in:
Micah Jerome Ellison 2020-12-26 16:13:12 -08:00
parent 91049eda6c
commit 2214efffcf
3 changed files with 18 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import sys
from .jrnl import run
from .args import parse_args
from .exception import ConfigDirectoryPathIsFileException
def configure_logger(debug=False):
@ -33,5 +34,9 @@ def cli(manual_args=None):
return run(args)
except ConfigDirectoryPathIsFileException as e:
print(e, file=sys.stderr)
return 1
except KeyboardInterrupt:
return 1

View file

@ -7,6 +7,7 @@ import yaml
import xdg.BaseDirectory
from . import __version__
from .exception import ConfigDirectoryPathIsFileException
from .color import ERROR_COLOR
from .color import RESET_COLOR
from .output import list_journals
@ -33,7 +34,13 @@ def get_config_path():
except FileExistsError:
# .TODO raise a custom jrnl exception
# this is when XDG tries to create a directory with the same name as a file that exists
raise
raise ConfigDirectoryPathIsFileException(
"The path to your jrnl configuration directory is a file, not a directory:\n"
+ os.path.join(xdg.BaseDirectory.xdg_config_home, XDG_RESOURCE)
+ "\n"
+ "Removing this file will allow jrnl to save its configuration."
)
return os.path.join(
config_directory_path or os.path.expanduser("~"), DEFAULT_CONFIG_NAME

View file

@ -10,3 +10,8 @@ class UpgradeValidationException(Exception):
"""Raised when the contents of an upgraded journal do not match the old journal"""
pass
class ConfigDirectoryPathIsFileException(Exception):
pass