Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messaging on bad Pants version #156

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

navijation
Copy link

Resolves #155

Handle the case where the Github API returns multiple results due to an inexact release tag match
by raising a new TagNotFoundError which also links the Pants releases page. Also wrap the typical
CalledProcessError with this new exception.

@kaos kaos requested a review from jsirois April 10, 2023 18:32
Copy link
Contributor

@jsirois jsirois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @navneethjayendran. Are you up for adding a test?

That might go here as a call to a new test_bad_pants_version test function you'd add lower down:

test_pants_sha(scie_pants_scie);

github_api_response = ptex.fetch_json(github_api_url, **headers)
# If the response is a list, multiple matches were found, which means the supplied tag
# is not an exact match against any tag
if isinstance(github_api_response, list):
Copy link
Contributor

@jsirois jsirois Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it would make a bit more sense to keep the comment mostly unchanged but change the test to if not isinstance(github_api_response, dict) since that is what is used / relied upon on line 138 below. As it stands, if the API returned a string a bool or a number, the same style of confusing exception as this fixes would be raised.

@simon-liebehenschel
Copy link

simon-liebehenschel commented Jun 1, 2023

Thank you for this pull request. It will definitely improve a user experience.

It will be also great to improve the documentation page https://www.pantsbuild.org/docs/initial-configuration#create-pantstoml because "$PANTS_VERSION" is confusing. I set the value to 2.15 expecting that I can set the version that I see on the documentation page, but, as it turns out, this must be the exact Git tag (2.15.1). Adding a URL to the "releases" Github page may be enough to clarify the case.

@navijation navijation requested a review from jsirois July 13, 2023 05:51
@navijation navijation force-pushed the nav/improve-error-messaging-on-pants-version branch from 47232cf to 31a701a Compare July 13, 2023 05:55
@navijation
Copy link
Author

@jsirois Sorry for the long response time. I adjusted the check to look for a dict specifically. @AIGeneratedUsername I added a test case for this error message as you suggested.

@jsirois
Copy link
Contributor

jsirois commented Jul 20, 2023

@navneethjayendran thanks for picking this back up. It looks like there are test issue to work out still. I'm going to add a few folks as reviewers since I've stepped away from Pants-related development. They should be able to help you take this home or else recommend further reviewers.

@jsirois jsirois requested review from kaos and huonw July 20, 2023 16:43
Comment on lines 42 to +43
fn assert_stderr_output(command: &mut Command, expected_messages: Vec<&str>) -> Output {
let output = execute(command.stderr(Stdio::piped())).unwrap();
let output = execute_no_error(command.stderr(Stdio::piped()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry that this does no longer make the same assertion about the sub process' exit code as before for all the unrelated tests using this method now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would adding a separate assertion to those call sites make sense? It seems natural for a macro that inspects stderr contents to tolerate nonzero exit codes.

Copy link
Contributor

@huonw huonw Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of #296, callers of assert_stderr_output can indicate whether the command should either succeed or fail (and both are checked).

@huonw huonw requested a review from thejcannon July 20, 2023 22:55
@@ -117,12 +121,22 @@ def determine_tag_version(
github_api_url = (
f"https://api.github.com/repos/pantsbuild/pants/git/refs/tags/{urllib.parse.quote(tag)}"
)
github_releases_url = "https://github.com/pantsbuild/pants/releases"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we're actually about to switch to a GitHub Release-based approach for any version >=2.

If you're able to sit a smidge, this code might look different when we make that switch.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know when that happens and I can revisit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for waiting! The switch has happened now.

For version strings that look new (after PANTS_PEX_GITHUB_RELEASE_VERSION), this code path isn't used, as the function returns early. For older ones, definitely still worth considering improvements'; thanks!

For those new ones, Pants is then downloaded from GitHub directly, with some error handling about it not existing (but feel free to fine-tune if you have ideas!), in

pex_url = f"https://github.com/pantsbuild/pants/releases/download/release_{version}/{pex_name}"
if bootstrap_urls_path:
bootstrap_urls = json.loads(Path(bootstrap_urls_path).read_text())
urls_info = bootstrap_urls["ptex"]
pex_url = urls_info.get(pex_name)
if pex_url is None:
raise ValueError(
f"Couldn't find '{pex_name}' in PANTS_BOOTSTRAP_URLS file: '{bootstrap_urls_path}' "
"under the 'ptex' key."
)
if not isinstance(pex_url, str):
raise TypeError(
f"The value for the key '{pex_name}' in PANTS_BOOTSTRAP_URLS file: '{bootstrap_urls_path}' "
f"under the 'ptex' key was expected to be a string. Got a {type(pex_url).__name__}"
)
with tempfile.NamedTemporaryFile(suffix=".pex") as pants_pex:
try:
ptex.fetch_to_fp(pex_url, pants_pex.file)
except subprocess.CalledProcessError as e:
fatal(
f"Wasn't able to fetch the Pants PEX at {pex_url}.\n\n"
"Check to see if the URL is reachable (i.e. GitHub isn't down) and if"
f" {pex_name} asset exists within the release."
" If the asset doesn't exist it may be that this platform isn't yet supported."
" If that's the case, please reach out on Slack: https://www.pantsbuild.org/docs/getting-help#slack"
" or file an issue on GitHub: https://github.com/pantsbuild/pants/issues/new/choose.\n\n"
f"Exception:\n\n{e}"
)

@benjyw
Copy link
Contributor

benjyw commented Dec 20, 2023

Hi @navneethjayendran ! Just checking on the status of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scie-pants unhelpful error on ambiguous Pants version tag
8 participants