affaan-m/ECC · error · SystemExit

Unknown flag

Error message

Unknown flag: {arg}

What it means

Argument guard in parse_args: a command-line argument starting with '-' was encountered that is not the recognized --clear flag. The ws_listener accepts only --clear and an optional positional output directory; anything else dashed aborts startup.

Solutions

  1. Use only '--clear' or a bare positional output directory: python ws_listener.py /path/to/out
  2. Set VIDEODB_EVENTS_DIR env var instead of passing a directory flag
  3. Check the script's usage — there are no other flags supported

Example fix

// before
python ws_listener.py --dir ./events
// after
python ws_listener.py ./events
Defensive patterns

Strategy: validation

Validate before calling

allowed = {'--clear'}
bad = [a for a in sys.argv[1:] if a.startswith('-') and a not in allowed]
if bad:
    sys.exit(f'Unknown flag(s): {bad}')

Prevention

When it happens

Trigger: Running python ws_listener.py --dir ./out or --help or any unsupported flag like -v.

Common situations: Users assuming a full argparse-style interface; copy-pasting flags from other tools; expecting --help to work.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/72d5d517eeef9b52. Report an issue: GitHub.

Appendix: source

Thrown at skills/videodb/scripts/ws_listener.py:87

    """Create the listener state directory with private permissions."""
    path.mkdir(parents=True, exist_ok=True, mode=0o700)
    try:
        path.chmod(0o700)
    except OSError:
        pass
    return path


def parse_args() -> tuple[bool, Path]:
    clear = False
    output_dir: str | None = None
    
    args = sys.argv[1:]
    for arg in args:
        if arg == "--clear":
            clear = True
        elif arg.startswith("-"):
            raise SystemExit(f"Unknown flag: {arg}")
        elif not arg.startswith("-"):
            output_dir = arg
    
    if output_dir is None:
        events_dir = os.environ.get("VIDEODB_EVENTS_DIR")
        if events_dir:
            return clear, ensure_private_dir(Path(events_dir))
        return clear, ensure_private_dir(default_output_dir())

    return clear, ensure_private_dir(Path(output_dir))

CLEAR_EVENTS, OUTPUT_DIR = parse_args()
EVENTS_FILE = OUTPUT_DIR / "videodb_events.jsonl"
WS_ID_FILE = OUTPUT_DIR / "videodb_ws_id"
PID_FILE = OUTPUT_DIR / "videodb_ws_pid"

# Track if this is the first connection (for clearing events)
_first_connection = True

View on GitHub (pinned to 8321021c54)