1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2024-09-16 10:51:42 +02:00

Check the status of the cargo metadata command

This commit is contained in:
mo8it 2024-08-09 00:12:49 +02:00
parent e41c3a7c92
commit 337460d299

View File

@ -1,4 +1,4 @@
use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};
use serde::Deserialize;
use std::{
io::Read,
@ -68,12 +68,16 @@ impl CmdRunner {
.stdin(Stdio::null())
.stderr(Stdio::inherit())
.output()
.context(CARGO_METADATA_ERR)?
.stdout;
.context(CARGO_METADATA_ERR)?;
let target_dir = serde_json::de::from_slice::<CargoMetadata>(&metadata_output)
.context("Failed to read the field `target_directory` from the `cargo metadata` output")
.map(|metadata| metadata.target_directory)?;
if !metadata_output.status.success() {
bail!("The command `cargo metadata …` failed. Are you in the `rustlings/` directory?");
}
let target_dir = serde_json::de::from_slice::<CargoMetadata>(&metadata_output.stdout)
.context(
"Failed to read the field `target_directory` from the output of the command `cargo metadata …`",
)?.target_directory;
Ok(Self { target_dir })
}