Skip to content

Commit

Permalink
Add more structure to the warnings returned from crates.io publish
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed Dec 5, 2016
1 parent 7dd0f93 commit f697b8c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ fn transmit(config: &Config,
}, tarball);

match publish {
Ok(invalid_categories) => {
if !invalid_categories.is_empty() {
Ok(warnings) => {
if !warnings.invalid_categories.is_empty() {
let msg = format!("\
the following are not valid category slugs and were \
ignored: {}. Please see https://crates.io/category_slugs \
for the list of all category slugs. \
", invalid_categories.join(", "));
", warnings.invalid_categories.join(", "));
config.shell().warn(&msg)?;
}
Ok(())
Expand Down
8 changes: 6 additions & 2 deletions src/crates-io/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ pub struct User {
pub name: Option<String>,
}

pub struct Warnings {
pub invalid_categories: Vec<String>,
}

#[derive(RustcDecodable)] struct R { ok: bool }
#[derive(RustcDecodable)] struct ApiErrorList { errors: Vec<ApiError> }
#[derive(RustcDecodable)] struct ApiError { detail: String }
Expand Down Expand Up @@ -155,7 +159,7 @@ impl Registry {
}

pub fn publish(&mut self, krate: &NewCrate, tarball: &File)
-> Result<Vec<String>> {
-> Result<Warnings> {
let json = json::encode(krate)?;
// Prepare the body. The format of the upload request is:
//
Expand Down Expand Up @@ -215,7 +219,7 @@ impl Registry {
x.iter().flat_map(Json::as_string).map(Into::into).collect()
})
.unwrap_or_else(Vec::new);
Ok(invalid_categories)
Ok(Warnings { invalid_categories: invalid_categories })
}

pub fn search(&mut self, query: &str, limit: u8) -> Result<(Vec<Crate>, u32)> {
Expand Down

0 comments on commit f697b8c

Please sign in to comment.