Skip to content

Commit 337460d

Browse files
committed
Check the status of the cargo metadata command
1 parent e41c3a7 commit 337460d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/cmd.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{Context, Result};
1+
use anyhow::{bail, Context, Result};
22
use serde::Deserialize;
33
use std::{
44
io::Read,
@@ -68,12 +68,16 @@ impl CmdRunner {
6868
.stdin(Stdio::null())
6969
.stderr(Stdio::inherit())
7070
.output()
71-
.context(CARGO_METADATA_ERR)?
72-
.stdout;
71+
.context(CARGO_METADATA_ERR)?;
7372

74-
let target_dir = serde_json::de::from_slice::<CargoMetadata>(&metadata_output)
75-
.context("Failed to read the field `target_directory` from the `cargo metadata` output")
76-
.map(|metadata| metadata.target_directory)?;
73+
if !metadata_output.status.success() {
74+
bail!("The command `cargo metadata …` failed. Are you in the `rustlings/` directory?");
75+
}
76+
77+
let target_dir = serde_json::de::from_slice::<CargoMetadata>(&metadata_output.stdout)
78+
.context(
79+
"Failed to read the field `target_directory` from the output of the command `cargo metadata …`",
80+
)?.target_directory;
7781

7882
Ok(Self { target_dir })
7983
}

0 commit comments

Comments
 (0)