diff --git a/ethstaker_deposit/deposit.py b/ethstaker_deposit/deposit.py index 90fd4503..aa353fd2 100644 --- a/ethstaker_deposit/deposit.py +++ b/ethstaker_deposit/deposit.py @@ -31,7 +31,24 @@ def check_python_version() -> None: ''' if sys.version_info < (3, 9): click.pause(load_text(['err_python_version'])) - sys.exit() + sys.exit(78) + + +def check_term_encoding() -> None: + ''' + Checks that the terminal uses utf-8 encoding and exits if not. This is done to avoid issues with passwords + ''' + encoding = sys.stdin.encoding.lower() + acceptable_encodings = ['utf-8'] + + # Windows has a zoo of cp codepages, none of which map to utf-8, and utf-8 is generally not available + # "It is what it is" on Windows + if encoding not in acceptable_encodings and sys.platform != 'win32': + click.pause( + f'Your terminal is using {encoding} encoding which can present problems with passwords. ' + 'Please use "utf-8".' + ) + sys.exit(78) def check_connectivity() -> None: @@ -113,6 +130,7 @@ def cli(ctx: click.Context, language: str, non_interactive: bool, ignore_connect def run() -> None: freeze_support() # Needed when running under Windows in a frozen bundle check_python_version() + check_term_encoding() try: cli() diff --git a/tests/test_deposit.py b/tests/test_deposit.py index a7f4048d..48d03907 100644 --- a/tests/test_deposit.py +++ b/tests/test_deposit.py @@ -12,7 +12,7 @@ def test_should_notify_user_and_exit_if_invalid_python_version(monkeypatch) -> None: exit_called = False - def _mock_sys_exit(): + def _mock_sys_exit(arg): nonlocal exit_called exit_called = True