Skip to content

Commit d227b0e

Browse files
xtask: Refactor error message
Refactor "out of sync" manpages, tmt test files error messages out to a separate function. Also update the error message to ask to run `just update-generated` Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 9554949 commit d227b0e

3 files changed

Lines changed: 14 additions & 24 deletions

File tree

crates/xtask/src/man.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use serde::{Deserialize, Serialize};
1010
use std::{fs, io::Write};
1111
use xshell::{Shell, cmd};
1212

13+
use crate::out_of_sync_error;
14+
1315
/// Represents a CLI option extracted from the JSON dump
1416
#[derive(Debug, Serialize, Deserialize)]
1517
pub struct CliOption {
@@ -664,10 +666,7 @@ pub fn check_manpages(sh: &Shell) -> Result<()> {
664666
let filename = format!("bootc-{}.8.md", command_parts.join("-"));
665667
let filepath = Utf8Path::new("docs/src/man").join(&filename);
666668
if !filepath.exists() {
667-
anyhow::bail!(
668-
"{} is missing; run `cargo xtask update-generated` to create it",
669-
filepath
670-
);
669+
return out_of_sync_error(&format!("{filepath} is missing"));
671670
}
672671
}
673672

@@ -729,10 +728,7 @@ fn check_markdown_options(
729728
return Ok(());
730729
};
731730
if new_content != content {
732-
anyhow::bail!(
733-
"{} is out of date; run `cargo xtask update-generated` to update it",
734-
markdown_path
735-
);
731+
return out_of_sync_error(&format!("{markdown_path} is out of date"));
736732
}
737733
Ok(())
738734
}
@@ -750,10 +746,7 @@ fn check_markdown_subcommands(
750746
return Ok(());
751747
};
752748
if new_content != content {
753-
anyhow::bail!(
754-
"{} is out of date; run `cargo xtask update-generated` to update it",
755-
markdown_path
756-
);
749+
return out_of_sync_error(&format!("{markdown_path} is out of date"));
757750
}
758751
Ok(())
759752
}

crates/xtask/src/tmt.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const DISTRO_CENTOS_9: &str = "centos-9";
3434

3535
// Import the argument types from xtask.rs
3636
use crate::bcvk::BcvkInstallOpts;
37-
use crate::{RunTmtArgs, SealState, TmtProvisionArgs};
37+
use crate::{RunTmtArgs, SealState, TmtProvisionArgs, out_of_sync_error};
3838

3939
/// Generate a random alphanumeric suffix for VM names
4040
fn generate_random_suffix() -> String {
@@ -941,16 +941,10 @@ pub(crate) fn check_integration() -> Result<()> {
941941
.with_context(|| format!("Reading {}", integration_fmf_path))?;
942942

943943
if tests_generated != tests_on_disk {
944-
anyhow::bail!(
945-
"{} is out of date; run `cargo xtask update-generated` to update it",
946-
tests_fmf_path
947-
);
944+
return out_of_sync_error(&format!("{tests_fmf_path} is out of date"));
948945
}
949946
if integration_generated != integration_on_disk {
950-
anyhow::bail!(
951-
"{} is out of date; run `cargo xtask update-generated` to update it",
952-
integration_fmf_path
953-
);
947+
return out_of_sync_error(&format!("{integration_fmf_path} is out of date"));
954948
}
955949

956950
Ok(())

crates/xtask/src/xtask.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ const TAR_REPRODUCIBLE_OPTS: &[&str] = &[
4040
"--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime",
4141
];
4242

43+
/// Helper function to write out out-of-sync error messages for manpages, tmt tests
44+
fn out_of_sync_error(message: &str) -> Result<()> {
45+
anyhow::bail!("{}; run `just update-generated` to update it", message)
46+
}
47+
4348
/// Build tasks for bootc
4449
#[derive(Debug, Parser)]
4550
#[command(name = "xtask")]
@@ -623,9 +628,7 @@ fn check_json_schemas(sh: &Shell) -> Result<()> {
623628
let on_disk =
624629
std::fs::read_to_string(target).with_context(|| format!("Reading {target}"))?;
625630
if generated != on_disk {
626-
anyhow::bail!(
627-
"{target} is out of date; run `cargo xtask update-generated` to update it"
628-
);
631+
return out_of_sync_error(&format!("{target} is out of date"));
629632
}
630633
}
631634
Ok(())

0 commit comments

Comments
 (0)