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

improving error message if location header missing #35

Merged
merged 2 commits into from
Aug 6, 2022

Conversation

vsoch
Copy link
Contributor

@vsoch vsoch commented Jun 12, 2022

currently if the location header is missing for any reason on a blob push (typically because auth is missing or wrong scope) a later error will trigger about an invalid url scheme, and this is misleading. We should check that the location is defined earlier on and provide a more meaningful message.

The test case I used to produce this was providing a token locally with the wrong scope - the request went through the auth flow (but was unsuccessful) and ultimately returned 403, and there was a meaningful message about the error in r.json().

Signed-off-by: vsoch [email protected]

vsoch added 2 commits June 12, 2022 00:45
currently if the location header is missing for any reason (typically because auth
is missing or wrong scope) a later error will trigger about an invalid url scheme,
and this is misleading. We should check that the location is defined earlier on
and provide a more meaningful message

Signed-off-by: vsoch <[email protected]>
@FeynmanZhou
Copy link
Member

LGTM. But I suggest it would be better to have another reviewer approve it.

Copy link

@jharmison-redhat jharmison-redhat left a comment

Choose a reason for hiding this comment

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

Some typing nits. Otherwise looks okay to my eye.

@@ -290,6 +294,8 @@ def _put_upload(

# Location should be in the header
session_url = self._get_location(r, container)
if not session_url:

Choose a reason for hiding this comment

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

Would it make more sense here to use an identity check for None? Actually the _get_location method could use the same treatment, I think.

Choose a reason for hiding this comment

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

It may also make sense on line 320 to set the return type hint as Optional[str] in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could be that the location header is None or an empty string (servers can vary in how they handle it), so I think this check is appropriate!

@@ -352,6 +358,8 @@ def _chunked_upload(

# Location should be in the header
session_url = self._get_location(r, container)
if not session_url:

Choose a reason for hiding this comment

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

The same identity/equality consideration as above.

@vsoch
Copy link
Contributor Author

vsoch commented Jul 6, 2022

okay I think this should be good to merge given approval from an admin? We probably should discuss this later - if we can have some number of community reviews good enough to warrant merge (or if we should have a reliably way to ping an admin). At the moment I always feel badly bothering folks on the slack to do this task!

@jharmison-redhat
Copy link

I'm happy to poke my head in and question assumptions from time to time, however valuable you may find that. I looked through your open issues when I was pinged on Slack and might be able to help with some of your TODO at some point as well (like maybe the retry decorator as a way to ease into the codebase).

@vsoch
Copy link
Contributor Author

vsoch commented Aug 6, 2022

okay realizing we have two approvals! I think this is good to merge, we have to find a balance between reviews / asking managers that are already busy to trivially approve to merge. I'm thinking we should remove the latter requirement in favor of some number of community reviews.

@vsoch vsoch merged commit bd723c6 into main Aug 6, 2022
@vsoch vsoch deleted the improve-403-error-message branch August 6, 2022 17:18
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.

3 participants