diff --git a/crates/crates-io/lib.rs b/crates/crates-io/lib.rs index bd85e869748..00cc3e0590b 100644 --- a/crates/crates-io/lib.rs +++ b/crates/crates-io/lib.rs @@ -298,8 +298,21 @@ impl Registry { pub fn unyank(&mut self, krate: &str, version: &str) -> Result<()> { let body = self.put(&format!("/crates/{}/{}/unyank", krate, version), &[])?; - assert!(serde_json::from_str::(&body)?.ok); - Ok(()) + let body = if body.is_empty() { + r#"{"ok":false}"#.parse()? + } else { + body + }; + match serde_json::from_str::(&body) { + Ok(response) => { + if response.ok { + Ok(()) + } else { + bail!("ok is false in response body") + } + } + _ => bail!("failed to parse response body"), + } } fn put(&mut self, path: &str, b: &[u8]) -> Result { diff --git a/tests/testsuite/yank.rs b/tests/testsuite/yank.rs index 8b528046fd1..83c118be80d 100644 --- a/tests/testsuite/yank.rs +++ b/tests/testsuite/yank.rs @@ -35,4 +35,17 @@ fn simple() { p.cargo("yank --vers 0.0.1 --index") .arg(registry_url().to_string()) .run(); + + p.cargo("yank --undo --vers 0.0.1 --index") + .arg(registry_url().to_string()) + .with_status(101) + .with_stderr( + " Updating `[..]` index + Unyank foo:0.0.1 +error: failed to undo a yank + +Caused by: + ok is false in response body", + ) + .run(); }