{"record":{"id":"a8b6a434875c2020","repo":"cocoindex-io/cocoindex","slug":"invalid-kind-name-r-a8b6a4","errorCode":null,"errorMessage":"Invalid {kind}: {name!r}","messagePattern":"Invalid (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/zvec/_target.py","lineNumber":87,"sourceCode":"_DOC_ID_CHECKER: TypeChecker[str] = TypeChecker(str)\n_COLLECTION_KEY_CHECKER = TypeChecker(tuple[str, str])\n\nRowT = TypeVar(\"RowT\", default=dict[str, Any])\n\n\n# zvec rejects names that don't match its internal rule. We guard with a\n# conservative identifier allow-list before handing the name to zvec, which\n# mirrors the input-safety guidance for other connectors and gives a clear error\n# early.\n_IDENTIFIER_RE = re.compile(r\"^[A-Za-z_][A-Za-z0-9_]*$\")\n\n# zvec additionally rejects collection names shorter than 3 characters.\n_MIN_COLLECTION_NAME_LEN = 3\n\n\ndef _validate_identifier(name: str, kind: str = \"identifier\") -> None:\n    if not isinstance(name, str) or not _IDENTIFIER_RE.match(name):\n        raise ValueError(f\"Invalid {kind}: {name!r}\")\n\n\ndef _validate_collection_name(name: str) -> None:\n    _validate_identifier(name, \"collection name\")\n    if len(name) < _MIN_COLLECTION_NAME_LEN:\n        raise ValueError(\n            f\"Invalid collection name {name!r}: zvec requires at least \"\n            f\"{_MIN_COLLECTION_NAME_LEN} characters.\"\n        )\n\n\n# =============================================================================\n# Connection\n# =============================================================================\n\n\ndef _collection_option(enable_mmap: bool, *, read_only: bool = False) -> Any:\n    return _zvec.CollectionOption(read_only=read_only, enable_mmap=enable_mmap)","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/zvec/_target.py#L69-L105","documentation":"_validate_identifier raises ValueError when a name (identifier, collection name, index name, etc.) is not a string or fails the _IDENTIFIER_RE regex. zvec requires names matching the identifier pattern.","triggerScenarios":"Passing a collection/field name with invalid characters (spaces, dashes, leading digits, symbols), or a non-string value (e.g. an int or Path) as a name, via collection_target or derived from_class names.","commonSituations":"Building collection names from file paths or user input without sanitizing; dashes in names; programmatic names containing illegal characters.","solutions":["Use only [A-Za-z_][A-Za-z0-9_]-style names that match the identifier regex","Sanitize/transform programmatic names (e.g. replace '-' with '_')","Ensure the value is a str, not Path/int"],"exampleFix":"// before\ncollection_target(name=f\"docs-{tenant_id}\")\n// after\ncollection_target(name=f\"docs_{tenant_id}\")","handlingStrategy":"validation","validationCode":"import re\nIDENT = re.compile(r\"[A-Za-z_][A-Za-z0-9_]*\")\nassert isinstance(name, str) and IDENT.match(name), f\"bad name: {name!r}\"","typeGuard":"def is_valid_identifier(name: object) -> TypeGuard[str]:\n    return isinstance(name, str) and bool(re.fullmatch(r\"[A-Za-z_][A-Za-z0-9_]*\", name))","tryCatchPattern":"try:\n    target = zvec.collection_target(name=name, ...)\nexcept ValueError as e:\n    if str(e).startswith(\"Invalid\"):\n        name = re.sub(r\"\\W\", \"_\", name) or \"collection\"\n        target = zvec.collection_target(name=name, ...)\n    else:\n        raise","preventionTips":["Sanitize names derived from user input/paths before use","Avoid dashes and leading digits in collection/field names","Validate names at config load time"],"tags":["python","validation","naming","zvec"],"backgroundTag":"invalid-identifier-format","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}