Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report more details on build backend exception #8464

Merged
merged 2 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/poetry/installation/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
16 changes: 11 additions & 5 deletions tests/installation/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down