From 7dd0f932a864d97bef5da26a0e148fca3f06d448 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 29 Nov 2016 16:09:00 -0500 Subject: [PATCH] Have a fallback for an empty response This happens in tests. --- src/crates-io/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/crates-io/lib.rs b/src/crates-io/lib.rs index 12c195edb..e35d82440 100644 --- a/src/crates-io/lib.rs +++ b/src/crates-io/lib.rs @@ -202,7 +202,11 @@ impl Registry { body.read(buf).unwrap_or(0) })?; // Can't derive RustcDecodable because JSON has a key named "crate" :( - let response = Json::from_str(&body)?; + let response = if body.len() > 0 { + Json::from_str(&body)? + } else { + Json::from_str("{}")? + }; let invalid_categories: Vec = response .find_path(&["warnings", "invalid_categories"])