Skip to content

Give helpful error message when missing protocol #1096

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions meilisearch/_httprequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def send_request(
raise MeilisearchTimeoutError(str(err)) from err
except requests.exceptions.ConnectionError as err:
raise MeilisearchCommunicationError(str(err)) from err
except requests.exceptions.InvalidSchema as err:
if "://" not in self.config.url:
raise MeilisearchCommunicationError(
f"""
Invalid URL {self.config.url}, no scheme/protocol supplied.
Did you mean https://{self.config.url}?
"""
) from err

raise MeilisearchCommunicationError(str(err)) from err

def get(self, path: str) -> Any:
return self.send_request(requests.get, path)
Expand Down
9 changes: 9 additions & 0 deletions tests/errors/test_communication_error_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ def test_meilisearch_communication_error_host(mock_post):
client = meilisearch.Client("http://wrongurl:1234", MASTER_KEY)
with pytest.raises(MeilisearchCommunicationError):
client.create_index("some_index")


@patch("requests.post")
def test_meilisearch_communication_error_no_protocol(mock_post):
mock_post.configure_mock(__name__="post")
mock_post.side_effect = requests.exceptions.InvalidSchema()
client = meilisearch.Client("localhost:7700", MASTER_KEY)
with pytest.raises(MeilisearchCommunicationError, match="no scheme/protocol supplied."):
client.create_index("some_index")