-
Notifications
You must be signed in to change notification settings - Fork 88
Adds a way to prevent crashes from not having discord opened #261
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
base: master
Are you sure you want to change the base?
Conversation
|
Great idea. Looking into this for 4.7.0 |
Awesome to know ^^ Let me know once it gets merged! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds functionality to prevent crashes when Discord is not running by implementing connection state checking and graceful error handling. The main purpose is to allow applications to continue running without Discord Rich Presence when Discord is unavailable, with optional retry mechanisms.
- Added connection state checking before operations to prevent crashes
- Implemented
is_discord_available()method to detect Discord availability - Modified connection methods to return boolean success indicators instead of raising exceptions
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| pypresence/presence.py | Added connection state checks, error handling, and modified method signatures to remove type annotations |
| pypresence/baseclient.py | Added Discord availability detection, improved connection handling, and enhanced error handling with cleanup |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Added type annotations to BaseClient methods and attributes for better code clarity and static analysis. Improved error handling by catching specific exceptions and logging debug messages during connection checks and cleanup. Minor refactoring for consistency and maintainability.
Co-authored-by: Copilot <[email protected]>
Added type annotations to methods in Presence and AioPresence classes for improved code clarity and static analysis. Introduced logging for exception handling to aid in debugging, replacing silent exception handling with debug log messages.
I've updated my files according to the review. It should be good to go now ^^ |
Replaces ConnectionError with PyPresenceException when not connected to Discord and removes the message from InvalidPipe exception for consistency.
Enhanced the Presence.close method to handle cases where the socket writer is not present, ensuring proper cleanup of resources even on error. Also refactored the buttons example for cleaner imports and more concise code formatting.
Simplifies type annotations and exception handling in BaseClient and Presence classes. Removes unnecessary imports, improves error logging, and ensures consistent cleanup of resources. Adds more robust handling for connection errors and unexpected exceptions, and streamlines method signatures for clarity.
|
This is a breaking change, and will thus be pushed back until |
Hi there! While I was developing a simple 2D game engine, I relied on this to create presences. However, I discovered that if Discord wasn't running, the game or app would crash. To resolve this, I implemented a method to detect when Discord isn't running, preventing the app from crashing and enabling a reconnection retry feature.
Here's a Usage Example