diff --git a/src/krate.rs b/src/krate.rs index 2638c15798..0a3247b04d 100644 --- a/src/krate.rs +++ b/src/krate.rs @@ -745,11 +745,6 @@ pub fn new(req: &mut Request) -> CargoResult { let ignored_invalid_categories = try!( Category::update_crate(try!(req.tx()), &krate, &categories) ); - let warnings: Vec = - ignored_invalid_categories.iter().map(|category| { - format!("'{}' is not a recognized category name \ - and has been ignored.", category) - }).collect(); // Upload the crate to S3 let mut handle = req.app().handle(); @@ -808,7 +803,13 @@ pub fn new(req: &mut Request) -> CargoResult { bomb.path = None; #[derive(RustcEncodable)] - struct R { krate: EncodableCrate, warnings: Vec } + struct Warnings { invalid_categories: Vec } + let warnings = Warnings { + invalid_categories: ignored_invalid_categories, + }; + + #[derive(RustcEncodable)] + struct R { krate: EncodableCrate, warnings: Warnings } Ok(req.json(&R { krate: krate.minimal_encodable(), warnings: warnings })) } diff --git a/src/tests/krate.rs b/src/tests/krate.rs index 7b05ff4d92..2f9f75653b 100644 --- a/src/tests/krate.rs +++ b/src/tests/krate.rs @@ -26,7 +26,9 @@ struct CrateMeta { total: i32 } #[derive(RustcDecodable)] struct GitCrate { name: String, vers: String, deps: Vec, cksum: String } #[derive(RustcDecodable)] -struct GoodCrate { krate: EncodableCrate, warnings: Vec } +struct Warnings { invalid_categories: Vec } +#[derive(RustcDecodable)] +struct GoodCrate { krate: EncodableCrate, warnings: Warnings } #[derive(RustcDecodable)] struct CrateResponse { krate: EncodableCrate, versions: Vec, keywords: Vec } #[derive(RustcDecodable)] @@ -896,7 +898,7 @@ fn good_categories() { let json: GoodCrate = ::json(&mut response); assert_eq!(json.krate.name, "foo"); assert_eq!(json.krate.max_version, "1.0.0"); - assert_eq!(json.warnings.len(), 0); + assert_eq!(json.warnings.invalid_categories.len(), 0); } #[test] @@ -910,8 +912,7 @@ fn ignored_categories() { let json: GoodCrate = ::json(&mut response); assert_eq!(json.krate.name, "foo"); assert_eq!(json.krate.max_version, "1.0.0"); - assert_eq!(json.warnings, vec!["\'bar\' is not a recognized category name \ - and has been ignored.".to_string()]); + assert_eq!(json.warnings.invalid_categories, vec!["bar".to_string()]); } #[test]