Skip to content

empty-catch: sdks/python/pmxt/ws_client.py:132 — bare except Exception: pass during WebSocket close #1106

Description

@realfishsam

Violation

            except Exception:
                pass

(lines 130–133, inner try/except wrapping ws.close())

Location

sdks/python/pmxt/ws_client.py:132

Full context (lines 128–135):

except Exception as exc:
    last_error = exc
    try:
        ws.close()
    except Exception:
        pass
    if attempt < CONNECT_ATTEMPTS - 1:
        time.sleep(0.25 * (attempt + 1))

Why It Matters

ws.close() failing during a connection-retry teardown is silently discarded with no logging. If the exception type or message would reveal why the socket is stuck (e.g. a TLS or OS-level resource leak), that information is permanently lost. Debugging intermittent WebSocket issues becomes much harder.

Suggested Fix

At minimum log the suppressed error at DEBUG level so it appears in traces without disrupting the retry flow:

    except Exception as close_exc:
        logger.debug("ws.close() failed during retry teardown", {"error": str(close_exc)})

Found by automated code hygiene audit

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions