Skip to content

bare-except: sdks/python/pmxt/server_manager.py:73 — bare except catches SystemExit/KeyboardInterrupt in _get_port_from_url #813

@realfishsam

Description

@realfishsam

Violation

try:
    from urllib.parse import urlparse
    parsed = urlparse(url)
    return parsed.port or self.DEFAULT_PORT
except:
    return self.DEFAULT_PORT

Location

sdks/python/pmxt/server_manager.py:73

Why It Matters

A bare except: clause in Python catches all exceptions including SystemExit, KeyboardInterrupt, and GeneratorExit. This means a Ctrl-C issued while _get_port_from_url is on the call stack will be swallowed and the program will not exit. It should use except Exception: at minimum, and ideally the narrower except (ValueError, AttributeError): which are the only exceptions urlparse can realistically raise.

Suggested Fix

except (ValueError, AttributeError):
    return self.DEFAULT_PORT

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