-
Notifications
You must be signed in to change notification settings - Fork 308
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
Reformat HTTP errors #666
Reformat HTTP errors #666
Conversation
@pytest.fixture | ||
@pytest.fixture(scope="session") | ||
def sampleproject_dist(tmp_path_factory): | ||
checkout = tmp_path_factory.mktemp("sampleproject", numbered=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick fix to avoid a "file exists" error from mktemp
when this fixture is used in more than one test.
a027837
to
54c753c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sigmavirus24 I made the requested changes. If you're able, I think it'd be nice to merge today or tomorrow, to include in 3.2.0, but no worries if not.
twine/__main__.py
Outdated
status_code = exc.response.status_code | ||
status_phrase = http.HTTPStatus(status_code).phrase | ||
return ( | ||
f"{exc.__class__.__name__} from {exc.response.url}: " | ||
f"{status_code} {status_phrase}\n" | ||
f"{exc.response.reason}" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using HTTPStatus
from the standard library.
Codes and phrases: https://github.com/python/cpython/blob/935586845815f5b4c7814794413f6a812d4bd45f/Lib/http/__init__.py#L69
except exceptions.TwineException as exc: | ||
result = f"{exc.__class__.__name__}: {exc.args[0]}" | ||
|
||
return _format_error(result) if isinstance(result, str) else result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored in 3fd259a to one return
and one _format_error
to ensure that any current and future string results are treated as an error, which is how they're interpreted by sys.exit
.
Fixes #587, in which my main goal was to make the source and potential resolution of errors from Warehouse more obvious, which might have mitigated issues like #577 and #424.
New format:
Old format:
This intentionally wraps at 80 characters, but I've also seen reports where it wasn't wrapped, and the Warehouse URL was buried at the end of the line.