{"record":{"id":"6271e59f77f9b264","repo":"headroomlabs-ai/headroom","slug":"unknown-importance-context-context","errorCode":null,"errorMessage":"unknown importance context: {context}","messagePattern":"unknown importance context: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"headroom/transforms/error_detection.py","lineNumber":67,"sourceCode":")\n\n\ndef score_line(line: str, context: str = \"text\") -> tuple[str | None, float, float]:\n    \"\"\"Score `line` against the default Rust keyword detector.\n\n    Returns ``(category | None, priority, confidence)``. ``category`` is\n    one of ``error|warning|importance|security|markdown`` or ``None`` if\n    nothing matched.\n\n    Raises :class:`ValueError` for unknown context names. The Rust\n    binding returns ``None`` for unknown contexts to dodge a\n    pyo3-0.22 + clippy false positive on ``PyResult``-returning\n    ``#[pyfunction]``s; this shim translates that into the explicit\n    Python error every caller would expect.\n    \"\"\"\n    result = _rust_score_line(line, context)\n    if result is None:\n        raise ValueError(f\"unknown importance context: {context}\")\n    return cast(\"tuple[str | None, float, float]\", result)\n\n\n_REGISTRY: dict[str, list[str]] = _rust_keyword_registry_snapshot()\n\n\ndef _alternation(words: list[str]) -> str:\n    \"\"\"Compile a `\\b(w1|w2|…)\\b` regex source from the Rust-supplied list.\n\n    The keywords are static (compiled once on import) so we don't need\n    `re.escape` for the current set, but using it keeps the shim\n    correct if a future Rust update adds a regex meta-character.\n    \"\"\"\n    escaped = [re.escape(w) for w in words]\n    return r\"\\b(\" + \"|\".join(escaped) + r\")\\b\"\n\n\n# ─── Canonical keyword sets (pulled from Rust at import time) ───────────────","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/transforms/error_detection.py#L49-L85","documentation":"Raised by the Python shim around the Rust _rust_score_line in error_detection.py: the Rust binding returns None for unknown context names (to dodge a pyo3/clippy issue), and this shim converts that None into the explicit ValueError callers expect. Context names are the scoring contexts like error/warning/importance/security/markdown; anything else is rejected.","triggerScenarios":"Calling score_line (the shim) with a context string that is not one of the recognized contexts — typo like 'err' vs 'error', or a new context added on the caller side but not in the Rust keyword registry.","commonSituations":"Passing a context sourced from config or an LLM prompt; version skew where the Python package and the compiled Rust extension disagree on the context set.","solutions":["Use an exact, known context name (check the Rust keyword registry snapshot via the module's exposed registry).","Whitelist contexts at the call site before invoking score_line.","After upgrading the native extension, re-check the supported context list if you use non-core contexts."],"exampleFix":"# before\nscore_line(line, context=\"errors\")  # ValueError: unknown importance context\n\n# after\n_VALID_CONTEXTS = {\"error\", \"warning\", \"importance\", \"security\", \"markdown\"}\nscore_line(line, context=context if context in _VALID_CONTEXTS else \"importance\")","handlingStrategy":"validation","validationCode":"_VALID = {\"error\", \"warning\", \"importance\", \"security\", \"markdown\"}\nif context not in _VALID:\n    raise ValueError(f\"bad context {context!r}; expected one of {sorted(_VALID)}\")\nscore_line(line, context)","typeGuard":"def is_valid_importance_context(ctx: str) -> bool:\n    return ctx in {\"error\", \"warning\", \"importance\", \"security\", \"markdown\"}","tryCatchPattern":"try:\n    cat, prio, conf = score_line(line, context)\nexcept ValueError as e:\n    if \"unknown importance context\" in str(e):\n        cat, prio, conf = score_line(line, \"importance\")  # safe default\n    else:\n        raise","preventionTips":["Whitelist contexts before calling score_line.","Don't pass free-form/LLM-generated strings as context.","After upgrading the native extension, re-check the supported context set."],"tags":["validation","rust","pyo3","error-detection"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}