From fbbcfa24c5c7b09adaee0dc88b2d232a01282c42 Mon Sep 17 00:00:00 2001 From: Alexazhu Date: Sat, 18 Apr 2026 15:03:02 +0800 Subject: [PATCH] fix(matrix): preserve exception tracebacks on E2EE and auth failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Five ``except Exception as exc:`` blocks in the Matrix adapter logged only ``str(exc)`` without ``exc_info=True``: - _reverify_keys_after_upload → post-upload key verification failure - _upload_keys_if_needed → initial device-key query failure - _upload_keys_if_needed → re-upload device keys failure - _upload_keys_if_needed → initial device key upload failure - connect → whoami / access-token validation failure The E2EE key paths here are security-critical: a silent traceback- less failure during device-key verification or upload makes it hard for operators to tell whether their Matrix bot is failing because of a stale token, a federation timeout, or an olm state mismatch — all three fail with different tracebacks, which ``str(exc)`` alone flattens. The contributing guide asks for ``exc_info=True`` on error logs. Append it to each of the five call sites. Pure logging enrichment. --- gateway/platforms/matrix.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gateway/platforms/matrix.py b/gateway/platforms/matrix.py index 9afe18ee..313eb70c 100644 --- a/gateway/platforms/matrix.py +++ b/gateway/platforms/matrix.py @@ -329,7 +329,7 @@ class MatrixAdapter(BasePlatformAdapter): ) return False except Exception as exc: - logger.error("Matrix: post-upload key verification failed: %s", exc) + logger.error("Matrix: post-upload key verification failed: %s", exc, exc_info=True) return False return True @@ -345,6 +345,7 @@ class MatrixAdapter(BasePlatformAdapter): logger.error( "Matrix: cannot verify device keys on server: %s — refusing E2EE", exc, + exc_info=True, ) return False @@ -359,7 +360,7 @@ class MatrixAdapter(BasePlatformAdapter): try: await olm.share_keys() except Exception as exc: - logger.error("Matrix: failed to re-upload device keys: %s", exc) + logger.error("Matrix: failed to re-upload device keys: %s", exc, exc_info=True) return False return await self._reverify_keys_after_upload(client, local_ed25519) @@ -399,6 +400,7 @@ class MatrixAdapter(BasePlatformAdapter): "Try generating a new access token to get a fresh device.", client.device_id, exc, + exc_info=True, ) return False return await self._reverify_keys_after_upload(client, local_ed25519) @@ -468,6 +470,7 @@ class MatrixAdapter(BasePlatformAdapter): logger.error( "Matrix: whoami failed — check MATRIX_ACCESS_TOKEN and MATRIX_HOMESERVER: %s", exc, + exc_info=True, ) await api.session.close() return False