Skip to content
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

Pass CRT error, if it exists, into completion function #563

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions awscrt/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions awscrt/mqtt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,11 +1391,15 @@ 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
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()
future.add_done_callback(_on_complete)
Expand Down
8 changes: 4 additions & 4 deletions source/mqtt5_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions source/mqtt_client_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading