Skip to content

Commit 8c401a2

Browse files
committed
refactor(publish): Move reporting up a level
This gives us access to more context and makes it easier to see how other timeout reporting happens.
1 parent a7be79b commit 8c401a2

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

src/cargo/ops/registry/publish.rs

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,41 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
270270
DEFAULT_TIMEOUT
271271
};
272272
if 0 < timeout {
273+
let source_description = source.source_id().to_string();
274+
let short_pkg_descriptions = package_list(to_confirm.iter().copied(), "or");
275+
opts.gctx.shell().note(format!(
276+
"waiting for {short_pkg_descriptions} to be available at {source_description}.\n\
277+
You may press ctrl-c to skip waiting; the crate should be available shortly."
278+
))?;
279+
273280
let timeout = Duration::from_secs(timeout);
274-
wait_for_any_publish_confirmation(
281+
let confirmed = wait_for_any_publish_confirmation(
275282
opts.gctx,
276283
source_ids.original,
277284
&to_confirm,
278285
timeout,
279-
)?
286+
)?;
287+
if !confirmed.is_empty() {
288+
let short_pkg_description = confirmed
289+
.iter()
290+
.map(|pkg| format!("{} v{}", pkg.name(), pkg.version()))
291+
.sorted()
292+
.join(", ");
293+
opts.gctx.shell().status(
294+
"Published",
295+
format!("{short_pkg_description} at {source_description}"),
296+
)?;
297+
} else {
298+
let short_pkg_descriptions = package_list(to_confirm.iter().copied(), "or");
299+
opts.gctx.shell().warn(format!(
300+
"timed out waiting for {short_pkg_descriptions} to be available in {source_description}",
301+
))?;
302+
opts.gctx.shell().note(
303+
"the registry may have a backlog that is delaying making the \
304+
crate available. The crate should be available soon.",
305+
)?;
306+
}
307+
confirmed
280308
} else {
281309
BTreeSet::new()
282310
}
@@ -317,17 +345,10 @@ fn wait_for_any_publish_confirmation(
317345
// of independent progress bars can be a little confusing. There is an
318346
// overall progress bar managed here.
319347
source.set_quiet(true);
320-
let source_description = source.source_id().to_string();
321348

322349
let now = std::time::Instant::now();
323350
let sleep_time = Duration::from_secs(1);
324351
let max = timeout.as_secs() as usize;
325-
// Short does not include the registry name.
326-
let short_pkg_descriptions = package_list(pkgs.iter().copied(), "or");
327-
gctx.shell().note(format!(
328-
"waiting for {short_pkg_descriptions} to be available at {source_description}.\n\
329-
You may press ctrl-c to skip waiting; the crate should be available shortly."
330-
))?;
331352
let mut progress = Progress::with_style("Waiting", ProgressStyle::Ratio, gctx);
332353
progress.tick_now(0, max, "")?;
333354
let available = loop {
@@ -356,30 +377,12 @@ fn wait_for_any_publish_confirmation(
356377

357378
let elapsed = now.elapsed();
358379
if timeout < elapsed {
359-
gctx.shell().warn(format!(
360-
"timed out waiting for {short_pkg_descriptions} to be available in {source_description}",
361-
))?;
362-
gctx.shell().note(
363-
"the registry may have a backlog that is delaying making the \
364-
crate available. The crate should be available soon.",
365-
)?;
366380
break BTreeSet::new();
367381
}
368382

369383
progress.tick_now(elapsed.as_secs() as usize, max, "")?;
370384
std::thread::sleep(sleep_time);
371385
};
372-
if !available.is_empty() {
373-
let short_pkg_description = available
374-
.iter()
375-
.map(|pkg| format!("{} v{}", pkg.name(), pkg.version()))
376-
.sorted()
377-
.join(", ");
378-
gctx.shell().status(
379-
"Published",
380-
format!("{short_pkg_description} at {source_description}"),
381-
)?;
382-
}
383386

384387
Ok(available)
385388
}

0 commit comments

Comments
 (0)