{"record":{"id":"97afeddfd72c57f5","repo":"subframe7536/maple-font","slug":"id-should-0-and-100-in-character-variants-cur","errorCode":null,"errorMessage":"id should > 0 and < 100 in Character Variants, current is {id}","messagePattern":"id should > 0 and < 100 in Character Variants, current is (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/py/feature/ast.py","lineNumber":130,"sourceCode":"        self.desc = desc\n        self.example = example\n        Feature.__init__(self, tag, content, version)\n\n    def desc_item(self):\n        return f\"- [v{self.version}] {self.tag}: {self.desc}\"\n\n\nclass CharacterVariant(FeatureWithDocs):\n    def __init__(\n        self,\n        id: int,\n        desc: str,\n        content: Clazz | Lookup | Line | list,\n        version: str,\n        example: str,\n    ):\n        if id < 1 or id > 99:\n            raise TypeError(\n                f\"id should > 0 and < 100 in Character Variants, current is {id}\"\n            )\n        FeatureWithDocs.__init__(\n            self,\n            id=id,\n            tag=f\"cv{id:02d}\",\n            desc=desc,\n            content=content,\n            version=version,\n            example=example,\n        )\n\n    def get_name_lines(self) -> list[Line]:\n        _name = re.sub(\n            REGEXP, \"\", self.desc.replace(\"`\", \"\").replace(EMPTY_FEAT_SYMBOL, \" \")\n        ).strip()\n        return [\n            Line(\"cvParameters {\"),","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/subframe7536/maple-font/blob/c08fda97fef73d68c1755219852150770f6e6578/source/py/feature/ast.py#L112-L148","documentation":"Character Variants (cvXX) OpenType features are identified by an id 1–99, which the library formats as the tag cv01–cv99. FeatureWithDocs subclasses for Character Variants validate id in __init__ and raise TypeError when the id is out of range, because ids outside 1–99 cannot produce a valid two-digit cv tag. This is a constructor-time constraint, so it fires as soon as the feature object is created.","triggerScenarios":"Constructing a Character Variants feature (any class whose __init__ checks `if id < 1 or id > 99`) with id=0, a negative id, or id >= 100.","commonSituations":"Using a 0-based index straight from a loop without adding 1; defining cv100 for a 'hundredth' variant not realizing the OpenType cv tag space stops at cv99; loading a config file where ids were serialized off-by-one.","solutions":["Set the feature id to an integer in the range 1–99.","If you need more than 99 variants, split them across additional feature types or reuse/merge existing cv ids.","Clamp/validate ids from external config before constructing: `if not 1 <= id <= 99: skip or remap`."],"exampleFix":"// before\nCharacterVariants(id=100, desc='...', content=..., version='1.0', example='...')\n// after\nid = 100\nassert 1 <= id <= 99, f'cv id must be 1-99, got {id}'\nCharacterVariants(id=99, desc='...', content=..., version='1.0', example='...')","handlingStrategy":"validation","validationCode":"def check_cv_id(id):\n    if not isinstance(id, int) or not (1 <= id <= 99):\n        raise ValueError(f'cv id must be int 1-99, got {id}')\n\ncheck_cv_id(id)\nfeature = CharacterVariants(id=id, ...)","typeGuard":"def is_valid_cv_id(id) -> bool:\n    return isinstance(id, int) and 1 <= id <= 99","tryCatchPattern":"try:\n    feature = CharacterVariants(id=id, desc=desc, content=content, version=version, example=example)\nexcept TypeError as e:\n    if 'Character Variants' in str(e):\n        logging.error(f'remap cv id {id} into 1-99')\n        id = min(max(int(id), 1), 99)\n        feature = CharacterVariants(id=id, desc=desc, content=content, version=version, example=example)\n    else:\n        raise","preventionTips":["Generate cv ids from 1-based enumerations, never raw zero-based loop indices.","Remember the OpenType cv tag space ends at cv99; plan variants within 99 slots.","Validate ids from external config before constructing feature objects."],"tags":["python","typeerror","range-validation","character-variants","opentype-features"],"backgroundTag":"id-out-of-range","analyzedSha":"c08fda97fef73d68c1755219852150770f6e6578","analyzedAt":"2026-08-28T22:07:29.503Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}