feat: Exit with exception, not with exit1
this aligns to how other parts of the code work - leaving "exit" to the outermost caller.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
from logging import Formatter
|
from logging import Formatter
|
||||||
from logging.handlers import RotatingFileHandler, SysLogHandler
|
from logging.handlers import RotatingFileHandler, SysLogHandler
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -97,7 +96,7 @@ def setup_logging(config: Config) -> None:
|
|||||||
backupCount=10,
|
backupCount=10,
|
||||||
)
|
)
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
logger.error(
|
raise OperationalException(
|
||||||
f'Failed to create or access log file "{logfile_path.absolute()}". '
|
f'Failed to create or access log file "{logfile_path.absolute()}". '
|
||||||
"Please make sure you have the write permission to the log file or its parent "
|
"Please make sure you have the write permission to the log file or its parent "
|
||||||
"directories. If you're running freqtrade using docker, you see this error "
|
"directories. If you're running freqtrade using docker, you see this error "
|
||||||
@@ -105,7 +104,6 @@ def setup_logging(config: Config) -> None:
|
|||||||
"non-root user, delete and recreate the directories you need, and then try "
|
"non-root user, delete and recreate the directories you need, and then try "
|
||||||
"again."
|
"again."
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
|
||||||
handler_rf.setFormatter(Formatter(LOGFORMAT))
|
handler_rf.setFormatter(Formatter(LOGFORMAT))
|
||||||
logging.root.addHandler(handler_rf)
|
logging.root.addHandler(handler_rf)
|
||||||
|
|
||||||
|
|||||||
@@ -121,9 +121,8 @@ def test_set_loggers_Filehandler_without_permission(tmp_path):
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup_logging_pre()
|
setup_logging_pre()
|
||||||
with pytest.raises(SystemExit) as excinfo:
|
with pytest.raises(OperationalException):
|
||||||
setup_logging(config)
|
setup_logging(config)
|
||||||
assert excinfo.value.code == 1
|
|
||||||
|
|
||||||
logger.handlers = orig_handlers
|
logger.handlers = orig_handlers
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user