Capture FtBaseException at the outermost level
This commit is contained in:
parent
1ffda29fd2
commit
8e9a3e8fc8
@ -1,21 +1,27 @@
|
|||||||
|
|
||||||
|
|
||||||
class DependencyException(Exception):
|
class FreqtradeException(Exception):
|
||||||
|
"""
|
||||||
|
Freqtrade base exception. Handled at the outermost level.
|
||||||
|
All other exception types are subclasses of this exception type.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class OperationalException(FreqtradeException):
|
||||||
|
"""
|
||||||
|
Requires manual intervention and will stop the bot.
|
||||||
|
Most of the time, this is caused by an invalid Configuration.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class DependencyException(FreqtradeException):
|
||||||
"""
|
"""
|
||||||
Indicates that an assumed dependency is not met.
|
Indicates that an assumed dependency is not met.
|
||||||
This could happen when there is currently not enough money on the account.
|
This could happen when there is currently not enough money on the account.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class OperationalException(Exception):
|
class InvalidOrderException(FreqtradeException):
|
||||||
"""
|
|
||||||
Requires manual intervention and will usually stop the bot.
|
|
||||||
This happens when an exchange returns an unexpected error during runtime
|
|
||||||
or given configuration is invalid.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidOrderException(Exception):
|
|
||||||
"""
|
"""
|
||||||
This is returned when the order is not valid. Example:
|
This is returned when the order is not valid. Example:
|
||||||
If stoploss on exchange order is hit, then trying to cancel the order
|
If stoploss on exchange order is hit, then trying to cancel the order
|
||||||
@ -23,7 +29,7 @@ class InvalidOrderException(Exception):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class TemporaryError(Exception):
|
class TemporaryError(FreqtradeException):
|
||||||
"""
|
"""
|
||||||
Temporary network or exchange related error.
|
Temporary network or exchange related error.
|
||||||
This could happen when an exchange is congested, unavailable, or the user
|
This could happen when an exchange is congested, unavailable, or the user
|
||||||
|
@ -4,6 +4,7 @@ Main Freqtrade bot script.
|
|||||||
Read the documentation to know what cli arguments you need.
|
Read the documentation to know what cli arguments you need.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from freqtrade.exceptions import FreqtradeException, OperationalException
|
||||||
import sys
|
import sys
|
||||||
# check min. python version
|
# check min. python version
|
||||||
if sys.version_info < (3, 6):
|
if sys.version_info < (3, 6):
|
||||||
@ -14,7 +15,6 @@ import logging
|
|||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
|
|
||||||
from freqtrade.configuration import Arguments
|
from freqtrade.configuration import Arguments
|
||||||
from freqtrade.exceptions import OperationalException
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('freqtrade')
|
logger = logging.getLogger('freqtrade')
|
||||||
@ -50,7 +50,7 @@ def main(sysargv: List[str] = None) -> None:
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logger.info('SIGINT received, aborting ...')
|
logger.info('SIGINT received, aborting ...')
|
||||||
return_code = 0
|
return_code = 0
|
||||||
except OperationalException as e:
|
except FreqtradeException as e:
|
||||||
logger.error(str(e))
|
logger.error(str(e))
|
||||||
return_code = 2
|
return_code = 2
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -6,7 +6,7 @@ from unittest.mock import MagicMock, PropertyMock
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from freqtrade.configuration import Arguments
|
from freqtrade.configuration import Arguments
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException, FreqtradeException
|
||||||
from freqtrade.freqtradebot import FreqtradeBot
|
from freqtrade.freqtradebot import FreqtradeBot
|
||||||
from freqtrade.main import main
|
from freqtrade.main import main
|
||||||
from freqtrade.state import State
|
from freqtrade.state import State
|
||||||
@ -96,7 +96,7 @@ def test_main_operational_exception(mocker, default_conf, caplog) -> None:
|
|||||||
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.cleanup', MagicMock())
|
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.cleanup', MagicMock())
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.worker.Worker._worker',
|
'freqtrade.worker.Worker._worker',
|
||||||
MagicMock(side_effect=OperationalException('Oh snap!'))
|
MagicMock(side_effect=FreqtradeException('Oh snap!'))
|
||||||
)
|
)
|
||||||
patched_configuration_load_config_file(mocker, default_conf)
|
patched_configuration_load_config_file(mocker, default_conf)
|
||||||
mocker.patch('freqtrade.wallets.Wallets.update', MagicMock())
|
mocker.patch('freqtrade.wallets.Wallets.update', MagicMock())
|
||||||
|
Loading…
Reference in New Issue
Block a user