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

client: improve error messaging on connection failure #398

Merged
merged 5 commits into from
Jan 16, 2025

Conversation

ParthSareen
Copy link
Contributor

@ParthSareen ParthSareen commented Dec 29, 2024

Error messaging is unclear - especially on connection error
Also exposed the status code coming down but I'm not sure if we want that behavior

  • Tests

Sorry, something went wrong.

@ParthSareen ParthSareen changed the title Improve error messaging on connection failure client: Improve error messaging on connection failure Dec 29, 2024
@ParthSareen ParthSareen force-pushed the parth/qol-improve-connection-error-message branch from 2d717e6 to efe8e57 Compare December 29, 2024 22:52
Comment on lines +528 to +540
def __str__(self) -> str:
return f'{self.error} (status code: {self.status_code})'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

status code does not get printed currently - this exposes it

Copy link
Collaborator

Choose a reason for hiding this comment

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

What does it currently output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No code, just the message from the server:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

vs with the change:
image

@ParthSareen ParthSareen marked this pull request as ready for review December 29, 2024 22:55
@ParthSareen ParthSareen force-pushed the parth/qol-improve-connection-error-message branch from efe8e57 to db25d87 Compare December 29, 2024 23:02
@ParthSareen ParthSareen force-pushed the parth/qol-improve-connection-error-message branch 2 times, most recently from cd62955 to 03e494e Compare January 7, 2025 18:50
@ParthSareen ParthSareen force-pushed the parth/qol-improve-connection-error-message branch from 03e494e to 1eb18ec Compare January 15, 2025 19:42
@ParthSareen ParthSareen changed the title client: Improve error messaging on connection failure client: improve error messaging on connection failure Jan 15, 2025
Comment on lines +528 to +540
def __str__(self) -> str:
return f'{self.error} (status code: {self.status_code})'
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does it currently output?

Comment on lines 1119 to 1121
with pytest.raises(ConnectionError) as exc_info:
client.chat('model', messages=[{'role': 'user', 'content': 'prompt'}])
assert str(exc_info.value) == 'Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/download'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
with pytest.raises(ConnectionError) as exc_info:
client.chat('model', messages=[{'role': 'user', 'content': 'prompt'}])
assert str(exc_info.value) == 'Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/download'
with pytest.raises(ConnectionError, match='Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/download'):
client.chat('model', messages=[{'role': 'user', 'content': 'prompt'}])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice - didn't know of this pattern this is cool

Verified

This commit was signed with the committer’s verified signature.
jacobtylerwalls Jacob Walls
@ParthSareen ParthSareen force-pushed the parth/qol-improve-connection-error-message branch from 73e207a to 0c343dd Compare January 16, 2025 21:41
@ParthSareen ParthSareen merged commit 967fd65 into main Jan 16, 2025
7 checks passed
@ParthSareen ParthSareen deleted the parth/qol-improve-connection-error-message branch January 16, 2025 21:55
pressdarling pushed a commit to pressdarling/ollama-python that referenced this pull request Feb 1, 2025
*iImprove error messaging on connection failure
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.

None yet

3 participants