{"record":{"id":"72d5d517eeef9b52","repo":"affaan-m/ECC","slug":"unknown-flag-arg","errorCode":null,"errorMessage":"Unknown flag: {arg}","messagePattern":"Unknown flag: (.+?)","errorType":"exception","errorClass":"SystemExit","httpStatus":null,"severity":"warning","filePath":"skills/videodb/scripts/ws_listener.py","lineNumber":87,"sourceCode":"    \"\"\"Create the listener state directory with private permissions.\"\"\"\n    path.mkdir(parents=True, exist_ok=True, mode=0o700)\n    try:\n        path.chmod(0o700)\n    except OSError:\n        pass\n    return path\n\n\ndef parse_args() -> tuple[bool, Path]:\n    clear = False\n    output_dir: str | None = None\n    \n    args = sys.argv[1:]\n    for arg in args:\n        if arg == \"--clear\":\n            clear = True\n        elif arg.startswith(\"-\"):\n            raise SystemExit(f\"Unknown flag: {arg}\")\n        elif not arg.startswith(\"-\"):\n            output_dir = arg\n    \n    if output_dir is None:\n        events_dir = os.environ.get(\"VIDEODB_EVENTS_DIR\")\n        if events_dir:\n            return clear, ensure_private_dir(Path(events_dir))\n        return clear, ensure_private_dir(default_output_dir())\n\n    return clear, ensure_private_dir(Path(output_dir))\n\nCLEAR_EVENTS, OUTPUT_DIR = parse_args()\nEVENTS_FILE = OUTPUT_DIR / \"videodb_events.jsonl\"\nWS_ID_FILE = OUTPUT_DIR / \"videodb_ws_id\"\nPID_FILE = OUTPUT_DIR / \"videodb_ws_pid\"\n\n# Track if this is the first connection (for clearing events)\n_first_connection = True","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/skills/videodb/scripts/ws_listener.py#L69-L105","documentation":"ws_listener.parse_args() walks sys.argv and rejects any token starting with '-' that is not the single recognized '--clear' flag. It raises SystemExit (which prints the message and exits the process) — this is a CLI usage error, not a raised exception for callers to catch.","triggerScenarios":"Running `python ws_listener.py --port 8080`, `--help`, `-h`, `--output /tmp/x`, or any flag the minimal parser does not recognize.","commonSituations":"A user assumes standard flags exist (--help, --version, --output); a wrapper script passes through flags intended for a different tool; a typo such as `-clear` instead of `--clear`.","solutions":["Use the only supported flag, --clear, and an optional positional output directory.","Set VIDEODB_EVENTS_DIR in the environment instead of passing an output path via a flag.","Remove unsupported flags from wrapper scripts that invoke the listener."],"exampleFix":"# before\npython ws_listener.py --output /tmp/events\n\n# after\nVIDEODB_EVENTS_DIR=/tmp/events python ws_listener.py\n# or, positionally:\npython ws_listener.py /tmp/events","handlingStrategy":"validation","validationCode":"import sys\nSUPPORTED = {'--clear'}\ndef validate_argv() -> None:\n    for arg in sys.argv[1:]:\n        if arg.startswith('-') and arg not in SUPPORTED:\n            raise SystemExit(f'Unknown flag: {arg}. Supported: --clear, plus an optional positional output dir.')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use VIDEODB_EVENTS_DIR to set the output directory instead of inventing flags.","Remember the parser supports only --clear and a single positional directory argument.","If you need richer CLI behavior, wrap ws_listener with argparse in a separate entrypoint."],"tags":["cli","args","videodb","validation"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}