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

capture errors from cargo metadata #254

Merged
merged 3 commits into from
Jun 28, 2022
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
16 changes: 14 additions & 2 deletions setuptools_rust/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,21 @@ def build_extension(

# Execute cargo
try:
output = subprocess.check_output(command, env=env, encoding="latin-1")
output = subprocess.check_output(
command, env=env, encoding="latin-1", stderr=subprocess.PIPE
)
except subprocess.CalledProcessError as e:
raise CompileError(f"cargo failed with code: {e.returncode}\n{e.output}")
raise CompileError(
f"""
cargo failed with code: {e.returncode}

Output captured from stderr:
{e.stderr}

Output captured from stdout:
{e.stdout}
"""
)

except OSError:
raise DistutilsExecError(
Expand Down
27 changes: 26 additions & 1 deletion setuptools_rust/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,32 @@ def _metadata(self) -> "_CargoMetadata":
]
if self.cargo_manifest_args:
metadata_command.extend(self.cargo_manifest_args)
self._cargo_metadata = json.loads(subprocess.check_output(metadata_command))

try:
payload = subprocess.check_output(
metadata_command, encoding="latin-1", stderr=subprocess.PIPE
)
except subprocess.CalledProcessError as e:
raise DistutilsSetupError(
f"""
cargo metadata failed with code: {e.returncode}

Output captured from stderr:
{e.stderr}

Output captured from stdout:
{e.stdout}
"""
)
try:
self._cargo_metadata = json.loads(payload)
except json.decoder.JSONDecodeError as e:
raise DistutilsSetupError(
f"""
Error parsing output of cargo metadata as json; received:
{payload}
"""
) from e
return self._cargo_metadata

def _uses_exec_binding(self) -> bool:
Expand Down