-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
As a maintainability-focused developer, I want the exception handling in the websocket_endpoint function to be more granular so that specific issues can be easily diagnosed and the stability of the websocket connection is improved.
Background:
Currently, the websocket_endpoint function captures all exceptions broadly, which can hide underlying issues and make debugging difficult. Narrowing exception handling to specific exception types that are expected during stream operations (like network issues or stream errors) can enhance stability and debugging clarity. This change applies to the websocket_endpoint function in main.py, which manages WebSocket communications and message streaming from the Ollama model.
Risver:
- Modify the exception handling in
websocket_endpointto catch specific exceptions such aswebsockets.ConnectionClosed,RuntimeError, orstreaming.StreamError, instead of a broadException. - Ensure that the
finallyblock still properly closes the websocket connection regardless of what errors occur. - Verify that only the expected exceptions are caught, allowing unexpected issues to still propagate and be visible during testing.
- Document the change for debugging clarity and future maintainers.
- Test the WebSocket connection under scenarios like intentional disconnects, network errors, and stream errors, to confirm specific errors are captured and logged properly, and resources are cleaned up correctly.
- Confirm that the websocket does not remain open or corrupted after errors, ensuring proper resource cleanup.
- Ensure that in case of exceptions, the connection is closed gracefully and no residual open connections or unhandled errors occur.
- Test the stability and error logging to ensure errors are more specific and debugging is clearer.