From d8c01aed4486bcbef7ff9fc326eff1fc8a07340a Mon Sep 17 00:00:00 2001 From: Bret Ambrose Date: Mon, 29 Apr 2024 11:30:54 -0700 Subject: [PATCH 1/3] Pass CRT error, if it exists, into completion function --- awscrt/mqtt5.py | 7 +++++-- source/mqtt5_client.c | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/awscrt/mqtt5.py b/awscrt/mqtt5.py index 80dd0d002..8a4cbdde5 100644 --- a/awscrt/mqtt5.py +++ b/awscrt/mqtt5.py @@ -1391,11 +1391,14 @@ def __init__(self, client_options: ClientOptions): def _ws_handshake_transform(self, http_request_binding, http_headers_binding, native_userdata): if self._ws_handshake_transform_cb is None: - _awscrt.mqtt5_ws_handshake_transform_complete(None, native_userdata) + _awscrt.mqtt5_ws_handshake_transform_complete(None, native_userdata, 0) return def _on_complete(f): - _awscrt.mqtt5_ws_handshake_transform_complete(f.exception(), native_userdata) + error_code = 0 + if isinstance(f, exceptions.AwsCrtError): + error_code = f.code + _awscrt.mqtt5_ws_handshake_transform_complete(f.exception(), native_userdata, error_code) future = Future() future.add_done_callback(_on_complete) diff --git a/source/mqtt5_client.c b/source/mqtt5_client.c index 92e2b1ea1..eddc5ab7f 100644 --- a/source/mqtt5_client.c +++ b/source/mqtt5_client.c @@ -711,13 +711,13 @@ PyObject *aws_py_mqtt5_ws_handshake_transform_complete(PyObject *self, PyObject PyObject *exception_py; PyObject *ws_transform_capsule; - if (!PyArg_ParseTuple(args, "OO", &exception_py, &ws_transform_capsule)) { + int error_code = AWS_ERROR_SUCCESS; + if (!PyArg_ParseTuple(args, "OOi", &exception_py, &ws_transform_capsule, &error_code)) { return NULL; } - int error_code = AWS_ERROR_SUCCESS; - if (exception_py != Py_None) { - /* TODO: Translate Python exception to aws error. In the meantime here's a catch-all. */ + if (exception_py != Py_None && error_code == AWS_ERROR_SUCCESS) { + /* Fallback code for if the error source was outside the CRT native implementation */ error_code = AWS_ERROR_HTTP_CALLBACK_FAILURE; } From d5651876dfc4aad84fc92c50ef2d48a2437d567e Mon Sep 17 00:00:00 2001 From: Bret Ambrose Date: Mon, 29 Apr 2024 13:31:39 -0700 Subject: [PATCH 2/3] Let's actually find the right object before treating it like an exception --- awscrt/mqtt5.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/awscrt/mqtt5.py b/awscrt/mqtt5.py index 8a4cbdde5..4f8bff98d 100644 --- a/awscrt/mqtt5.py +++ b/awscrt/mqtt5.py @@ -1396,8 +1396,9 @@ def _ws_handshake_transform(self, http_request_binding, http_headers_binding, na def _on_complete(f): error_code = 0 - if isinstance(f, exceptions.AwsCrtError): - error_code = f.code + hs_exception = f.exception() + if isinstance(hs_exception, exceptions.AwsCrtError): + error_code = hs_exception.code _awscrt.mqtt5_ws_handshake_transform_complete(f.exception(), native_userdata, error_code) future = Future() From c3f7c0b284aa2865ba69af0919348ba644dbee5f Mon Sep 17 00:00:00 2001 From: Bret Ambrose Date: Mon, 29 Apr 2024 14:57:52 -0700 Subject: [PATCH 3/3] Mqtt311 support + workaround sphinx 7.3 issues --- .github/workflows/ci.yml | 2 +- .github/workflows/docs.yml | 2 +- awscrt/mqtt.py | 8 ++++++-- source/mqtt_client_connection.c | 8 ++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96b1f06c2..c2d00a14d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -272,7 +272,7 @@ jobs: submodules: true - name: Check docs run: | - python3 -m pip install sphinx + python3 -m pip install sphinx==7.2.6 python3 -m pip install --verbose . ./scripts/make-docs.py diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index a0ca31620..1a28f6464 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -20,7 +20,7 @@ jobs: - name: Update docs branch run: | - python3 -m pip install sphinx + python3 -m pip install sphinx==7.2.6 python3 -m pip install --verbose . ./scripts/make-docs.py diff --git a/awscrt/mqtt.py b/awscrt/mqtt.py index 5a96f5632..7529168ea 100644 --- a/awscrt/mqtt.py +++ b/awscrt/mqtt.py @@ -444,11 +444,15 @@ def _on_connection_resumed(self, return_code, session_present): def _ws_handshake_transform(self, http_request_binding, http_headers_binding, native_userdata): if self._ws_handshake_transform_cb is None: - _awscrt.mqtt_ws_handshake_transform_complete(None, native_userdata) + _awscrt.mqtt_ws_handshake_transform_complete(None, native_userdata, 0) return def _on_complete(f): - _awscrt.mqtt_ws_handshake_transform_complete(f.exception(), native_userdata) + error_code = 0 + hs_exception = f.exception() + if isinstance(hs_exception, awscrt.exceptions.AwsCrtError): + error_code = hs_exception.code + _awscrt.mqtt_ws_handshake_transform_complete(f.exception(), native_userdata, error_code) future = Future() future.add_done_callback(_on_complete) diff --git a/source/mqtt_client_connection.c b/source/mqtt_client_connection.c index 70da32835..9eb73a950 100644 --- a/source/mqtt_client_connection.c +++ b/source/mqtt_client_connection.c @@ -615,13 +615,13 @@ PyObject *aws_py_mqtt_ws_handshake_transform_complete(PyObject *self, PyObject * PyObject *exception_py; PyObject *ws_transform_capsule; - if (!PyArg_ParseTuple(args, "OO", &exception_py, &ws_transform_capsule)) { + int error_code = AWS_ERROR_SUCCESS; + if (!PyArg_ParseTuple(args, "OOi", &exception_py, &ws_transform_capsule, &error_code)) { return NULL; } - int error_code = AWS_ERROR_SUCCESS; - if (exception_py != Py_None) { - /* TODO: Translate Python exception to aws error. In the meantime here's a catch-all. */ + if (exception_py != Py_None && error_code == AWS_ERROR_SUCCESS) { + /* Fallback code for if the error source was outside the CRT native implementation */ error_code = AWS_ERROR_HTTP_CALLBACK_FAILURE; }