Skip to content

Commit

Permalink
report more details on build backend exception (#8464)
Browse files Browse the repository at this point in the history
Co-authored-by: Randy Döring <[email protected]>
  • Loading branch information
dimbleby and radoering authored Sep 24, 2023
1 parent e9d34f1 commit b6ebabf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
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

0 comments on commit b6ebabf

Please sign in to comment.