Skip to content

Commit 26ead88

Browse files
committed
publish: Change "unknown categories" warning to error
1 parent f08d605 commit 26ead88

File tree

3 files changed

+10
-49
lines changed

3 files changed

+10
-49
lines changed

src/controllers/krate/publish.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,12 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
384384

385385
// Update all categories for this crate, collecting any invalid categories
386386
// in order to be able to warn about them
387-
let ignored_invalid_categories = Category::update_crate(conn, &krate, &categories)?;
387+
let unknown_categories = Category::update_crate(conn, &krate, &categories)?;
388+
if !unknown_categories.is_empty() {
389+
let unknown_categories = unknown_categories.join(", ");
390+
let domain = &app.config.domain_name;
391+
return Err(bad_request(format!("The following category slugs are not currently supported on crates.io: {}\n\nSee https://{}/category_slugs for a list of supported slugs.", unknown_categories, domain)));
392+
}
388393

389394
let top_versions = krate.top_versions(conn)?;
390395

@@ -435,7 +440,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
435440
// that is no longer needed. As such, crates.io currently does not return any `other`
436441
// warnings at this time, but if we need to, the field is available.
437442
let warnings = PublishWarnings {
438-
invalid_categories: ignored_invalid_categories,
443+
invalid_categories: vec![],
439444
invalid_badges: vec![],
440445
other: vec![],
441446
};

src/tests/krate/publish/categories.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::new_category;
33
use crate::util::{RequestHelper, TestApp};
44
use googletest::prelude::*;
55
use http::StatusCode;
6-
use insta::assert_json_snapshot;
6+
use insta::{assert_json_snapshot, assert_snapshot};
77

88
#[tokio::test(flavor = "multi_thread")]
99
async fn good_categories() {
@@ -30,11 +30,8 @@ async fn ignored_categories() {
3030

3131
let crate_to_publish = PublishBuilder::new("foo_ignored_cat", "1.0.0").category("bar");
3232
let response = token.publish_crate(crate_to_publish).await;
33-
assert_eq!(response.status(), StatusCode::OK);
34-
assert_json_snapshot!(response.json(), {
35-
".crate.created_at" => "[datetime]",
36-
".crate.updated_at" => "[datetime]",
37-
});
33+
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
34+
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"The following category slugs are not currently supported on crates.io: bar\n\nSee https://crates.io/category_slugs for a list of supported slugs."}]}"#);
3835
}
3936

4037
#[tokio::test(flavor = "multi_thread")]

src/tests/krate/publish/snapshots/all__krate__publish__categories__ignored_categories.snap

-41
This file was deleted.

0 commit comments

Comments
 (0)