eclipse-paho / eclipse-paho/paho.mqtt.python

Examples ignore errors, because Client does not always raise exceptions

Open
#447 0 comments 0 reactions 0 assignees View on GitHub
Status: Available Type: Enhancement
Dominant language
Python
Stars
2.4k
Forks
742
Avg merge
12d 48m
Merged PRs (30d)
1

Description

The current API uses error return codes (see #142), which needs to be checked for each relevant call. However, documentation does not mention it, and the examples do not so it either.

For example. https://github.com/eclipse/paho.mqtt.python/blob/master/examples/client_sub.py says:
```
mqttc.connect("mqtt.eclipse.org", 1883, 60)
mqttc.subscribe("$SYS/#", 0)
```

The correct code would be:
```
result = mqttc.connect("mqtt.eclipse.org", 1883, 60)
if result != mqtt.MQTT_ERR_SUCCESS:
raise Exception("mqtt connect failed: " + mqtt.error_string(result))

result, mid = mqttc.subscribe("$SYS/#", 0)
if result != mqtt.MQTT_ERR_SUCCESS:
raise Exception("mqtt subscribe failed: " + mqtt.error_string(result))
```

I think that either:
- Every example should be fixed to properly error-check
- .. or an API should be changed to always raise on error.

(I personally prefer latter solution, because that's how every other python library works)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.