diff options
author | Joffrey F <joffrey@docker.com> | 2017-10-16 12:41:29 -0700 |
---|---|---|
committer | Joffrey F <f.joffrey@gmail.com> | 2017-10-17 17:20:00 -0700 |
commit | d8194cf6f0c5fd5a08f1a0daa6b4022a5582d008 (patch) | |
tree | 23d14d73bd81c8ba2303c2d31bea6ee2bae1e403 | |
parent | 0ec77bf7d58f6a273cb8ae0b65a26f15e13bd6e0 (diff) |
Add specific handling for pywintypes.error
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r-- | compose/cli/errors.py | 20 | ||||
-rw-r--r-- | tests/unit/cli/errors_test.py | 21 |
2 files changed, 41 insertions, 0 deletions
diff --git a/compose/cli/errors.py b/compose/cli/errors.py index 23e065c9..1506aa66 100644 --- a/compose/cli/errors.py +++ b/compose/cli/errors.py @@ -57,6 +57,26 @@ def handle_connection_errors(client): except (ReadTimeout, socket.timeout) as e: log_timeout_error(client.timeout) raise ConnectionError() + except Exception as e: + if is_windows(): + import pywintypes + if isinstance(e, pywintypes.error): + log_windows_pipe_error(e) + raise ConnectionError() + raise + + +def log_windows_pipe_error(exc): + if exc.winerror == 232: # https://github.com/docker/compose/issues/5005 + log.error( + "The current Compose file version is not compatible with your engine version. " + "Please upgrade your Compose file to a more recent version, or set " + "a COMPOSE_API_VERSION in your environment." + ) + else: + log.error( + "Windows named pipe error: {} (code: {})".format(exc.strerror, exc.winerror) + ) def log_timeout_error(timeout): diff --git a/tests/unit/cli/errors_test.py b/tests/unit/cli/errors_test.py index 7406a888..68326d1c 100644 --- a/tests/unit/cli/errors_test.py +++ b/tests/unit/cli/errors_test.py @@ -7,6 +7,7 @@ from requests.exceptions import ConnectionError from compose.cli import errors from compose.cli.errors import handle_connection_errors +from compose.const import IS_WINDOWS_PLATFORM from tests import mock @@ -65,3 +66,23 @@ class TestHandleConnectionErrors(object): raise APIError(None, None, msg) mock_logging.error.assert_called_once_with(msg) + + @pytest.mark.skipif(not IS_WINDOWS_PLATFORM, reason='Needs pywin32') + def test_windows_pipe_error_no_data(self, mock_logging): + import pywintypes + with pytest.raises(errors.ConnectionError): + with handle_connection_errors(mock.Mock(api_version='1.22')): + raise pywintypes.error(232, 'WriteFile', 'The pipe is being closed.') + + _, args, _ = mock_logging.error.mock_calls[0] + assert "The current Compose file version is not compatible with your engine version." in args[0] + + @pytest.mark.skipif(not IS_WINDOWS_PLATFORM, reason='Needs pywin32') + def test_windows_pipe_error_misc(self, mock_logging): + import pywintypes + with pytest.raises(errors.ConnectionError): + with handle_connection_errors(mock.Mock(api_version='1.22')): + raise pywintypes.error(231, 'WriteFile', 'The pipe is busy.') + + _, args, _ = mock_logging.error.mock_calls[0] + assert "Windows named pipe error: The pipe is busy. (code: 231)" == args[0] |