-
Notifications
You must be signed in to change notification settings - Fork 730
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
Exceptions and undefined variables are not raised within callback handlers #365
Comments
Instead of raising the error, v1.4 logs the error (using _easy_log function).
You can modify your above code to log error messages using on_log callback. For example,
|
Thank you, @tarunw07, that works, and I wasn't aware of that. Is this "designed to be so"? I find it would be a great improvement if the documentation were to state that explicitly. |
I think it is designed to be so. I agree that it should be mentioned in the documentation. I will try to update the documentation if I get any free time. |
Personally I find this behaviour of silently eating exceptions annoying and not a very good practice. A change would be much appreciated ;) |
When running the above example, the script simply hangs after logging the exception until I pass a KeyboardInterrupt. How would I gracefully fail the script when raising an exception within callback handlers? I was attempting to catch bad users/passwords, and raise an exception within on_connect, so that I could handle these failed attempts, however the best I can do is to stop the loop, with the script still hung.
|
https://www.python.org/dev/peps/pep-0020/ This issue is really annoying, exceptions should be raised properly and not be silenced. |
Silently eating exceptions makes debugging and development much harder. |
Seconding. I'm currently getting an log message, |
Argh, I have wasted hours and I am sure many others have too. Please consider changing this. |
Wasted hours this week, really miserable. Agree that they should NOT be swallowed, make an option to swallow but default off. |
We had issues with this in the past as well. We needed to implement new communication channels to get around this. |
They can optionally be suppressed by setting `client.suppress_exceptions = True`. Closes eclipse-paho#365.
Hello, that seems to be fixed right now (thanks a ton!), but how do we handle exceptions? For example, If I have an Exception raised in a callback (function added via |
This was a major change of default behaviour and as such probably should not have happened on point release, it probably should have been saved for 1.6 not a change from 1.5.0 to 1.5.1. While I understand why the change has been made, this is as likely to break existing code as it is to solve peoples frustrations with not knowing what happened. @mxmaxime It looks like you would have to put a try/expect block as the top level construct in your callback e.g.
|
@hardillb I still have an issue with this: the thread dies with an exception, but I cannot catch it in the caller thread. That's a problem because my application has multiple threads, and I want the whole thing to die in case of error in my callback. I've solved that in other threaded modules by saving the exception in a class MyClassError(Exception):
def __init__(self, message):
self.message = f"{message}"
super().__init__(self.message)
class MyClass()::
# other stuff...
def rx(self):
try:
while True:
do_your_thing()
except Exception as e:
self.exc = MyClassError(f"An unexpected error occurred: {e}")
return
def run(self):
self.rx_thread.start()
self.rx_thread.join()
if self.exc is not None:
raise self.exc Since But in the paho case, I don't know where to raise it in order to be caught in the main thread? |
Exceptions (e.g. missing variables) are not raised from within callback handlers nor is there any indication that the program is failing.
Install latest version of paho.mqtt
Run the following short program
What happens
The program connects to the MQTT broker, but neither subscribes nor does it show any sign of doing anything on the console.
Expectations
I'd expect the
raise
withinon_connect()
to cause an undefined error, and I would expect the raise and thethis_is_not_defined
variable to also cause such errors.Platforms
I have tested this on
The text was updated successfully, but these errors were encountered: