Repository navigation
Print the response content when upload fails - #337
Conversation
Codecov Report
@@ Coverage Diff @@
## master #337 +/- ##
==========================================
- Coverage 69.55% 68.84% -0.72%
==========================================
Files 12 12
Lines 588 597 +9
Branches 93 95 +2
==========================================
+ Hits 409 411 +2
- Misses 150 157 +7
Partials 29 29
Continue to review full report at Codecov.
|
|
This looks reasonably good to me - Ian? |
|
I'll comment on the UX of it, not the code... While I do agree the message should come from the server, I'm not sure if the response text should just be printed as is. Basically, if we're printing a json object, it doesn't look clean. Maybe twine should try to parse the contents of the response assuming it is formatted how it currently is and extract the error message and code from it. Failing that, just print whatever was the response. |
|
@pradyunsg I think that would only be possible if we can guarantee that every PyPI server would return errors formatted the exact same way. Webservers and APIs in general can return multiple types of errors; some may return JSON, some may return HTML, some may return nothing. Unless all PyPI servers always return JSON and always return the same object format of |
|
To be clear, I'm fine with this PR going in as is. I'm just trying to improve the UX of it - happier if it's cleaner. You are correct. Until we have a standard format, likely specified by a PEP, we can't reasonably expect that the response will take this format - this is why I'm suggesting falling back to printing the message as is if there's a different format. I don't think we have lose anything with this - one (common?) case improves, the rest of them stay as is. We increase the code complexity a bit for it. |
|
@pradyunsg I don't think Twine can parse a response body. However, I have exactly the same concerns as you. If someone sends this to a random server, that responds with an unruly and large HTML body, their terminal will be flooded with nonsense that's unhelpful. It may be wise to hide this behind a |
|
@sigmavirus24 I think |
7255911 to
fd352b4
Compare
|
@sigmavirus24 @pradyunsg @brainwane I've updated my commit to go the I also added a little breadcrumb where if the upload fails with an HTTP error, but Note: I also had to update 2 tests to comply with the new signature for the Let me know if you have any other suggestions. |
fd352b4 to
4525c47
Compare
The content will often contain an actual error message from the server, while the status code and reason may not. This change adds a `--verbose` option to the `upload` positional argument which will print the response content if an upload fails with an HTTP error.
4525c47 to
2fcac82
Compare
pradyunsg
left a comment
There was a problem hiding this comment.
Looks good to me, functionally. :)
|
The change looks good. It'd be good to have tests but I'll leave that decision in your hands @brainwane |
|
@sigmavirus24 I thought about adding a test for this, but there are a few issues I ran into:
Let me know if anyone has a better idea of a good test for this, and I'd be happy to add it. |
|
Thanks @jessejoe! |
Recently we hit an issue using twine to upload to artifactory where uploads would fail with a suspicious
HTTPError: 400 Client Error: Bad Request for url. This happened to coincide very close to SSL certificate changes, so we were debugging the certs, debugging the docker images, pretty much everything except twine itself. After many dead-ends I thought I would debug the HTTP response that twine is getting from the artifactory server where our internal PyPi repo is. This finally gave me an error message from the response that I could look into:This led me to https://www.jfrog.com/jira/browse/RTFACT-16189 which is a bug in artifactory not being able to handle packages built with newer versions of
wheel/setuptools/twinethat have metadata increased to v2.1.Had the content from the server been in the output from twine, it would have saved so much time. It's very common for servers to reply with error messages in the content, so it seems this could help lots of debugging out there.
I'm not positive this is the best place to put the change. My change catches the requests exception from
raise_for_status(), prints the response content, and then re-raises the exception. I'm happy to change this if another approach is better.Here is the output from twine without my change:
Here is the output with my change:
UPDATE
See #issuecomment-381730323 for updated changes to this PR.