Skip to content

Commit c24cbd4

Browse files
authored
Add validation for pants_version format (#338)
Implemented a check to ensure the 'pants_version' follows the 'major.minor.micro' format. This update raises a clear error message if the version string does not meet the expected format, enhancing user guidance and preventing configuration errors. Fix #337
1 parent 7691160 commit c24cbd4

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

package/src/test.rs

+31
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ pub(crate) fn run_integration_tests(
129129
test_ignore_empty_pants_version_pants_sha(scie_pants_scie);
130130

131131
test_pants_from_pex_version(scie_pants_scie);
132+
test_pants_from_bad_pex_version(scie_pants_scie);
132133

133134
let clone_root = create_tempdir()?;
134135
test_use_in_repo_with_pants_script(scie_pants_scie, &clone_root);
@@ -460,6 +461,36 @@ fn test_pants_from_pex_version(scie_pants_scie: &Path) {
460461
);
461462
}
462463

464+
fn test_pants_from_bad_pex_version(scie_pants_scie: &Path) {
465+
integration_test!(
466+
"Verify the output of scie-pants is user-friendly if they provide an invalid pants version"
467+
);
468+
469+
let tmpdir = create_tempdir().unwrap();
470+
471+
let pants_release = "2.18";
472+
let pants_toml_content = format!(
473+
r#"
474+
[GLOBAL]
475+
pants_version = "{pants_release}"
476+
"#
477+
);
478+
let pants_toml = tmpdir.path().join("pants.toml");
479+
write_file(&pants_toml, false, pants_toml_content).unwrap();
480+
481+
let err = execute(
482+
Command::new(scie_pants_scie)
483+
.arg("-V")
484+
.current_dir(&tmpdir)
485+
.stderr(Stdio::piped()),
486+
)
487+
.unwrap_err();
488+
489+
let error_text = err.to_string();
490+
assert!(error_text.contains("Wasn't able to fetch the Pants PEX at"));
491+
assert!(error_text.contains("Pants version format not recognized. Please add `.<patch_version>` to the end of the version. For example: `2.18` -> `2.18.0`"));
492+
}
493+
463494
fn test_use_in_repo_with_pants_script(scie_pants_scie: &Path, clone_root: &TempDir) {
464495
integration_test!("Verify scie-pants can be used as `pants` in a repo with the `pants` script");
465496
// This verifies a fix for https://github.com/pantsbuild/scie-pants/issues/28.

tools/src/scie_pants/install_pants.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,14 @@ def install_pants_from_pex(
105105
try:
106106
ptex.fetch_to_fp(pex_url, pants_pex.file)
107107
except subprocess.CalledProcessError as e:
108+
# if there's only one dot in version, specifically suggest adding the `.patch`)
109+
suggestion = (
110+
"Pants version format not recognized. Please add `.<patch_version>` to the end of the version. For example: `2.18` -> `2.18.0`.\n\n"
111+
if version.base_version.count(".") < 2
112+
else ""
113+
)
108114
fatal(
109-
f"Wasn't able to fetch the Pants PEX at {pex_url}.\n\n"
115+
f"Wasn't able to fetch the Pants PEX at {pex_url}.\n\n{suggestion}"
110116
"Check to see if the URL is reachable (i.e. GitHub isn't down) and if"
111117
f" {pex_name} asset exists within the release."
112118
" If the asset doesn't exist it may be that this platform isn't yet supported."

0 commit comments

Comments
 (0)