Improve error messaging on bad Pants version#156
Improve error messaging on bad Pants version#156navijation wants to merge 4 commits intopantsbuild:mainfrom
Conversation
jsirois
left a comment
There was a problem hiding this comment.
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:
scie-pants/package/src/test.rs
Line 98 in b92a076
| 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): |
There was a problem hiding this comment.
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.
|
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 |
47232cf to
31a701a
Compare
|
@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. |
|
@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. |
| 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())); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
As of #296, callers of assert_stderr_output can indicate whether the command should either succeed or fail (and both are checked).
| 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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Let me know when that happens and I can revisit.
There was a problem hiding this comment.
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
scie-pants/tools/src/scie_pants/install_pants.py
Lines 88 to 116 in 91477f6
|
Hi @navneethjayendran ! Just checking on the status of this? |
Resolves #155
Handle the case where the Github API returns multiple results due to an inexact release tag match
by raising a new
TagNotFoundErrorwhich also links the Pants releases page. Also wrap the typicalCalledProcessErrorwith this new exception.