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

FIX: give useful error msg when bad URL passed to BlobClient.from_blob_url() #23996

Merged
merged 3 commits into from
Apr 18, 2022

Conversation

pat-hearps
Copy link
Contributor

Description

Problem: A user tries to use BlobClient.from_blob_url() with an incorrect URL that does not have a container name and blob path, e.g. BlobClient.from_blob_url("https://testaccount.blob.core.windows.net/containername/") - note the missing blobname after the containername
Current Behaviour: User gets obscure error message: Because the list path_blob only has length of 1, i.e. ["containername"].

>       container_name, blob_name = unquote(path_blob[-2]), unquote(path_blob[-1])
E       IndexError: list index out of range

Fixed Behaviour: raises more helpful error: ValueError("Invalid URL. Provide a blob_url with a valid blob and container name.")

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.
  • Test 'test_from_blob_url_too_short_url()added totest_blob_client.py`

Pat added 2 commits April 14, 2022 10:02
If the user has not supplied a container name and blob path, then trying to access path_blob[-2] may result in a list IndexError due to the path_blob list only having a single element. This length check first should stop this from occurring.
@ghost ghost added Storage Storage Service (Queues, Blobs, Files) customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Apr 14, 2022
@ghost
Copy link

ghost commented Apr 14, 2022

Thank you for your contribution pat-hearps! We will review the pull request and get back to you soon.

@ghost
Copy link

ghost commented Apr 14, 2022

CLA assistant check
All CLA requirements met.

Copy link
Member

@jalauzon-msft jalauzon-msft left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Just one minor comment and then we should be able to get this merged.

With duplicated error message refactored out into string variable
@jalauzon-msft jalauzon-msft merged commit 9594828 into Azure:main Apr 18, 2022
@jalauzon-msft
Copy link
Member

Thanks again @pat-hearps Patrick for your contribution! I've merged your change in and it will be part of the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants