Skip to content

Commit b045fb2

Browse files
committed
Make formatting of error messages more consistent
Also remove duplicated code.
1 parent 31cc426 commit b045fb2

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

src/errors.rs

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -425,60 +425,51 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &
425425
if cs.len() == 1 {
426426
let _ = write!(
427427
buf,
428-
"component {} is unavailable for download for channel {}{}",
428+
"component {} is unavailable for download for channel '{}'\n",
429429
&cs[0].description(manifest),
430430
toolchain,
431-
if toolchain.starts_with("nightly") {
432-
"\nSometimes not all components are available in any given nightly. "
433-
} else {
434-
" "
435-
}
436431
);
437-
432+
if toolchain.starts_with("nightly") {
433+
let _ = write!(
434+
buf,
435+
"Sometimes not all components are available in any given nightly. "
436+
);
437+
}
438438
let _ = write!(
439439
buf,
440440
"If you don't need the component, you can remove it with:\n\n{}",
441441
remove_component_msg(&cs[0], manifest, toolchain)
442442
);
443443
} else {
444+
// More than one component
445+
444446
let same_target = cs
445447
.iter()
446448
.all(|c| c.target == cs[0].target || c.target.is_none());
447-
if same_target {
448-
let cs_str = cs
449-
.iter()
449+
450+
let cs_str = if same_target {
451+
cs.iter()
450452
.map(|c| format!("'{}'", c.short_name(manifest)))
451453
.collect::<Vec<_>>()
452-
.join(", ");
453-
let remove_msg = cs
454-
.iter()
455-
.map(|c| remove_component_msg(c, manifest, toolchain))
456-
.collect::<Vec<_>>()
457-
.join("\n");
458-
let _ = write!(
459-
buf,
460-
"some components unavailable for download for channel {}: {}
461-
If you don't need the components, you can remove them with:\n\n{}\n\n{}",
462-
toolchain, cs_str, remove_msg, TOOLSTATE_MSG,
463-
);
454+
.join(", ")
464455
} else {
465-
let cs_str = cs
466-
.iter()
456+
cs.iter()
467457
.map(|c| c.description(manifest))
468458
.collect::<Vec<_>>()
469-
.join(", ");
470-
let remove_msg = cs
471-
.iter()
472-
.map(|c| remove_component_msg(c, manifest, toolchain))
473-
.collect::<Vec<_>>()
474-
.join("\n");
475-
let _ = write!(
476-
buf,
477-
"some components unavailable for download for channel {}: {}
478-
If you don't need the components, you can remove them with:\n{}\n{}",
479-
toolchain, cs_str, remove_msg, TOOLSTATE_MSG,
480-
);
481-
}
459+
.join(", ")
460+
};
461+
462+
let remove_msg = cs
463+
.iter()
464+
.map(|c| remove_component_msg(c, manifest, toolchain))
465+
.collect::<Vec<_>>()
466+
.join("\n");
467+
let _ = write!(
468+
buf,
469+
"some components unavailable for download for channel '{}': {}\n\
470+
If you don't need the components, you can remove them with:\n\n{}\n\n{}",
471+
toolchain, cs_str, remove_msg, TOOLSTATE_MSG,
472+
);
482473
}
483474

484475
String::from_utf8(buf).unwrap()

0 commit comments

Comments
 (0)