diff --git a/src/poetry/installation/chef.py b/src/poetry/installation/chef.py index b1bea28540d..18e99ae49bf 100644 --- a/src/poetry/installation/chef.py +++ b/src/poetry/installation/chef.py @@ -137,14 +137,12 @@ def _prepare( ) except BuildBackendException as e: message_parts = [str(e)] - if isinstance(e.exception, CalledProcessError) and ( - e.exception.stdout is not None or e.exception.stderr is not None - ): - message_parts.append( - decode(e.exception.stderr) - if e.exception.stderr is not None - else decode(e.exception.stdout) - ) + if isinstance(e.exception, CalledProcessError): + text = e.exception.stderr or e.exception.stdout + if text is not None: + message_parts.append(decode(text)) + else: + message_parts.append(str(e.exception)) error = ChefBuildError("\n\n".join(message_parts)) diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index 3a921711242..1f08861feb2 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -1238,9 +1238,17 @@ def test_executor_fallback_on_poetry_create_error_without_wheel_installer( @pytest.mark.parametrize("failing_method", ["build", "get_requires_for_build"]) +@pytest.mark.parametrize( + "exception", + [ + CalledProcessError(1, ["pip"], output=b"original error"), + Exception("original error"), + ], +) @pytest.mark.parametrize("editable", [False, True]) def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess( failing_method: str, + exception: Exception, editable: bool, mocker: MockerFixture, config: Config, @@ -1250,9 +1258,7 @@ def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess( env: MockEnv, fixture_dir: FixtureDirGetter, ) -> None: - error = BuildBackendException( - CalledProcessError(1, ["pip"], output=b"Error on stdout") - ) + error = BuildBackendException(exception, description="hide the original error") mocker.patch.object(ProjectBuilder, failing_method, side_effect=error) io.set_verbosity(Verbosity.NORMAL) @@ -1282,10 +1288,10 @@ def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess( ChefBuildError - Backend operation failed: CalledProcessError(1, ['pip']) + hide the original error \ - Error on stdout + original error """ assert directory_package.source_url is not None