{"record":{"id":"a85a77a2186f9339","repo":"tirth8205/code-review-graph","slug":"toml-parsing-requires-the-tomli-package-on-pytho","errorCode":null,"errorMessage":"TOML parsing requires the 'tomli' package on Python < 3.11. Install it with:  pip install tomli","messagePattern":"TOML parsing requires the 'tomli' package on Python < 3\\.11\\. Install it with:  pip install tomli","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"code_review_graph/daemon.py","lineNumber":161,"sourceCode":"# ---------------------------------------------------------------------------\n# Loading\n# ---------------------------------------------------------------------------\n\n\ndef load_config(path: Path | None = None) -> DaemonConfig:\n    \"\"\"Load daemon configuration from a TOML file.\n\n    Args:\n        path: Explicit config path.  Falls back to :func:`default_config_path`.\n\n    Returns:\n        A fully-validated :class:`DaemonConfig`.\n\n    Raises:\n        RuntimeError: If ``tomllib`` / ``tomli`` is unavailable on Python < 3.11.\n    \"\"\"\n    if tomllib is None:\n        raise RuntimeError(\n            \"TOML parsing requires the 'tomli' package on Python < 3.11. \"\n            \"Install it with:  pip install tomli\"\n        )\n\n    config_path = path or default_config_path()\n\n    if not config_path.exists():\n        logger.info(\"Config file not found at %s — using defaults\", config_path)\n        return DaemonConfig()\n\n    with open(config_path, \"rb\") as fh:\n        raw: dict[str, Any] = tomllib.load(fh)\n\n    # -- [daemon] section ---------------------------------------------------\n    daemon_section: dict[str, Any] = raw.get(\"daemon\", {})\n    session_name: str = daemon_section.get(\"session_name\", \"crg-watch\")\n    log_dir = Path(daemon_section.get(\"log_dir\", str(DaemonConfig().log_dir)))\n    poll_interval: int = int(daemon_section.get(\"poll_interval\", 2))","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/tirth8205/code-review-graph/blob/b58668751ab0c7670c078cf7cbd4d1f5b8e54f81/code_review_graph/daemon.py#L143-L179","documentation":"load_config() parses TOML config files using tomllib (stdlib, Python 3.11+). On older Pythons it falls back to the optional tomli package; if tomli is not installed, tomllib is None and the function raises RuntimeError telling you to install tomli. Every daemon code path that reads config (startup, status, add/remove repo, config reload) goes through this function.","triggerScenarios":"Running the daemon (start/status/add/remove) on Python < 3.11 in an environment where the tomli package is not installed — e.g. it is missing from package extras or was pruned from a venv.","commonSituations":"Deploying to older Linux distros or CI images with Python 3.9/3.10, minimal containers, or installing the package from source without its optional dependencies.","solutions":["pip install tomli (or add it to requirements for Python < 3.11: 'tomli; python_version < \"3.11\"')","Upgrade the runtime to Python 3.11+ where tomllib is built in","Verify with `python -c \"import tomli\"` that the active venv actually has it"],"exampleFix":"# before\nRuntimeError: TOML parsing requires the 'tomli' package on Python < 3.11.\n\n# after\n$ pip install 'tomli; python_version < \"3.11\"'\n$ code-review-graph daemon start","handlingStrategy":"validation","validationCode":"import sys\nif sys.version_info < (3, 11):\n    try:\n        import tomli  # noqa: F401\n    except ImportError:\n        raise SystemExit(\"Install tomli: pip install tomli\")\n\nfrom code_review_graph.daemon import load_config\ncfg = load_config()","typeGuard":"def tomllib_available() -> bool:\n    import sys\n    if sys.version_info >= (3, 11):\n        return True\n    try:\n        import tomli  # noqa: F401\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"try:\n    cfg = load_config(path)\nexcept RuntimeError as e:\n    if 'tomli' in str(e):\n        subprocess.run([sys.executable, '-m', 'pip', 'install', 'tomli'], check=True)\n        cfg = load_config(path)\n    else:\n        raise","preventionTips":["Declare 'tomli; python_version < \"3.11\"' in requirements/pyproject","Pin CI/deploy images to Python 3.11+ to use stdlib tomllib","Smoke-test `import tomli` in deployment checks for older runtimes"],"tags":["python","dependency","toml","runtime-version"],"backgroundTag":"missing-optional-dependency","analyzedSha":"b58668751ab0c7670c078cf7cbd4d1f5b8e54f81","analyzedAt":"2026-08-28T13:19:08.966Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}