{"record":{"id":"0d48aae0f7352c8f","repo":"calesthio/OpenMontage","slug":"element-id-must-be-positive","errorCode":null,"errorMessage":"element_id must be positive","messagePattern":"element_id must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/_kling/elements.py","lineNumber":38,"sourceCode":"        return []\n    if not isinstance(element_list, list):\n        raise ValueError(\"element_list must be a list of element ids or objects\")\n\n    normalized: list[dict[str, int]] = []\n    for item in element_list:\n        raw_id: Any\n        if isinstance(item, dict):\n            raw_id = item.get(\"element_id\", item.get(\"id\"))\n        else:\n            raw_id = item\n        if raw_id is None:\n            raise ValueError(\"each element_list item must include element_id\")\n        try:\n            element_id = int(raw_id)\n        except (TypeError, ValueError) as exc:\n            raise ValueError(f\"element_id must be an integer-compatible value: {raw_id!r}\") from exc\n        if element_id <= 0:\n            raise ValueError(\"element_id must be positive\")\n        normalized.append({\"element_id\": element_id})\n    return normalized\n\n\ndef element_ids(element_list: Any | None) -> list[int]:\n    \"\"\"Return normalized element ids from an element reference list.\"\"\"\n\n    return [item[\"element_id\"] for item in normalize_element_list(element_list)]\n\n\ndef get_custom_element(element_id: int, client: KlingClient | None = None) -> dict[str, Any]:\n    \"\"\"Fetch one custom element for validation or diagnostics.\"\"\"\n\n    api = client or KlingClient()\n    return api.get(f\"/v1/general/advanced-custom-elements/{int(element_id)}\")\n\n\ndef list_custom_elements(","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/_kling/elements.py#L20-L56","documentation":"Raised after successful int conversion when the element id is zero or negative. Kling custom-element ids are positive integers, so this guard rejects invalid ids before they reach the API.","triggerScenarios":"Passing 0 as a placeholder/default id; negative ids from subtraction bugs or default -1 sentinels; numeric strings like '-5' or '0'.","commonSituations":"Uninitialized id variables (0) forwarded to the call; code using -1 as 'not found' sentinel and passing it through; off-by-one index math producing 0.","solutions":["Check where the id originates — an unset variable defaulting to 0 or -1 indicates a missing upstream lookup","Fetch the real id via the element creation/listing API before building element_list","Guard upstream: only append ids that are >= 1"],"exampleFix":"// before\nelement_id = -1  # 'not found' sentinel leaks into the call\nrefs = normalize_element_list([element_id])\n\n// after\nif element_id is None or element_id < 1:\n    raise LookupError('element id not resolved')\nrefs = normalize_element_list([element_id])","handlingStrategy":"validation","validationCode":"def is_positive_element_id(value) -> bool:\n    try:\n        return int(value) > 0\n    except (TypeError, ValueError):\n        return False","typeGuard":"def resolved_element_id(value) -> int | None:\n    try:\n        eid = int(value)\n    except (TypeError, ValueError):\n        return None\n    return eid if eid > 0 else None","tryCatchPattern":"try:\n    refs = normalize_element_list(items)\nexcept ValueError as e:\n    if 'positive' in str(e):\n        raise ValueError(f'unresolved element id (0 or negative): check upstream lookup') from e\n    raise","preventionTips":["Treat 0 or -1 ids as 'unresolved' upstream and fail the lookup, never forward them","Assert ids come from a real API response, not a default value","Filter ids with `if eid and eid > 0` before building element_list"],"tags":["kling","elements","validation","invalid-id"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}