You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add more context to publish-failed error message (#15879)
## What does this PR try to resolve?
This PR fixes issue #15754 where workspace publish failures provided
non-actionable error messages. Previously, when publishing a workspace
failed (due to rate limiting or other errors), users only saw generic
errors like `[ERROR] failed to publish to registry` without knowing
which package failed or what packages remained to be published.
## How to test and review this PR?
**Testing**: Run `cargo test workspace_publish_rate_limit_error` to see
the improved behavior, then `cargo test publish` to ensure all tests
pass.
**Review**:
- **Commit 1**: Adds test demonstrating current problematic behavior
- **Commit 2**: Implements fix and updates test to expect improved
output
The fix transforms error messages from generic `failed to publish to
registry` to actionable `failed to publish 'package_a' v0.1.0; the
following crates have not been published yet: package_b v0.1.0,
package_c v0.1.0`. This improvement applies consistently across all
publish error scenarios, giving users clear information about what went
wrong and what remains to be done.
[ERROR] failed to publish to registry at http://127.0.0.1:[..]/
3611
+
[ERROR] failed to publish foo v0.0.1 to registry at http://127.0.0.1:[..]/
3612
3612
3613
3613
Caused by:
3614
3614
token contains invalid characters.
@@ -4402,3 +4402,110 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
4402
4402
"#]])
4403
4403
.run();
4404
4404
}
4405
+
4406
+
#[cargo_test]
4407
+
fnworkspace_publish_rate_limit_error(){
4408
+
let registry = registry::RegistryBuilder::new()
4409
+
.http_api()
4410
+
.http_index()
4411
+
.add_responder("/api/v1/crates/new", |_req, _| {
4412
+
// For simplicity, let's just return rate limit error for all requests
4413
+
// This simulates hitting rate limit during workspace publish
4414
+
Response{
4415
+
code:429,
4416
+
headers:vec!["Retry-After: 3600".to_string()],
4417
+
body:format!(
4418
+
"You have published too many new crates in a short period of time. Please try again after Fri, 18 Jul 2025 20:00:34 GMT or email [email protected] to have your limit increased."
4419
+
).into_bytes(),
4420
+
}
4421
+
})
4422
+
.build();
4423
+
4424
+
let p = project()
4425
+
.file(
4426
+
"Cargo.toml",
4427
+
r#"
4428
+
[workspace]
4429
+
members = ["package_a", "package_b", "package_c"]
4430
+
"#,
4431
+
)
4432
+
.file("src/lib.rs","")
4433
+
.file(
4434
+
"package_a/Cargo.toml",
4435
+
r#"
4436
+
[package]
4437
+
name = "package_a"
4438
+
version = "0.1.0"
4439
+
edition = "2015"
4440
+
license = "MIT"
4441
+
description = "package a"
4442
+
repository = "https://github.com/test/package_a"
4443
+
"#,
4444
+
)
4445
+
.file("package_a/src/lib.rs","")
4446
+
.file(
4447
+
"package_b/Cargo.toml",
4448
+
r#"
4449
+
[package]
4450
+
name = "package_b"
4451
+
version = "0.1.0"
4452
+
edition = "2015"
4453
+
license = "MIT"
4454
+
description = "package b"
4455
+
repository = "https://github.com/test/package_b"
4456
+
"#,
4457
+
)
4458
+
.file("package_b/src/lib.rs","")
4459
+
.file(
4460
+
"package_c/Cargo.toml",
4461
+
r#"
4462
+
[package]
4463
+
name = "package_c"
4464
+
version = "0.1.0"
4465
+
edition = "2015"
4466
+
license = "MIT"
4467
+
description = "package c"
4468
+
repository = "https://github.com/test/package_c"
4469
+
4470
+
[dependencies]
4471
+
package_a = { version = "0.1.0", path = "../package_a" }
4472
+
"#,
4473
+
)
4474
+
.file("package_c/src/lib.rs","")
4475
+
.build();
4476
+
4477
+
// This demonstrates the improved error message after the fix
4478
+
// The user now knows which package failed and what packages remain to be published
[ERROR] failed to publish package_a v0.1.0 to registry at http://127.0.0.1:[..]/
4493
+
4494
+
[NOTE] the following crates have not been published yet:
4495
+
package_b v0.1.0 ([ROOT]/foo/package_b)
4496
+
package_c v0.1.0 ([ROOT]/foo/package_c)
4497
+
4498
+
Caused by:
4499
+
failed to get a 200 OK response, got 429
4500
+
headers:
4501
+
HTTP/1.1 429
4502
+
Content-Length: 172
4503
+
Connection: close
4504
+
Retry-After: 3600
4505
+
4506
+
body:
4507
+
You have published too many new crates in a short period of time. Please try again after Fri, 18 Jul 2025 20:00:34 GMT or email [email protected] to have your limit increased.
0 commit comments