{"id":"c52af0a4cc9b2a70","repo":"pypa/pip","slug":"filter-filtername-r-not-found","errorCode":null,"errorMessage":"filter {filtername!r} not found","messagePattern":"filter (.+?) not found","errorType":"exception","errorClass":"ClassNotFound","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/filters/__init__.py","lineNumber":42,"sourceCode":"    if filtername in FILTERS:\n        return FILTERS[filtername]\n    for name, cls in find_plugin_filters():\n        if name == filtername:\n            return cls\n    return None\n\n\ndef get_filter_by_name(filtername, **options):\n    \"\"\"Return an instantiated filter.\n\n    Options are passed to the filter initializer if wanted.\n    Raise a ClassNotFound if not found.\n    \"\"\"\n    cls = find_filter_class(filtername)\n    if cls:\n        return cls(**options)\n    else:\n        raise ClassNotFound(f'filter {filtername!r} not found')\n\n\ndef get_all_filters():\n    \"\"\"Return a generator of all filter names.\"\"\"\n    yield from FILTERS\n    for name, _ in find_plugin_filters():\n        yield name\n\n\ndef _replace_special(ttype, value, regex, specialttype,\n                     replacefunc=lambda x: x):\n    last = 0\n    for match in regex.finditer(value):\n        start, end = match.start(), match.end()\n        if start != last:\n            yield ttype, value[last:start]\n        yield specialttype, replacefunc(value[start:end])\n        last = end","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pygments/filters/__init__.py#L24-L60","documentation":"Raised as ClassNotFound by get_filter_by_name() when the requested filter name is neither in the built-in FILTERS dict nor provided by a pygments plugin (find_plugin_filters). The message echoes the offending name so the caller can correct it.","triggerScenarios":"Calling get_filter_by_name('codetag') with a misspelled name; find_filter_class returns None for both the built-in table and plugins, so ClassNotFound is raised.","commonSituations":"Typo in the filter name, referencing a filter from a plugin that is not installed, or a name that changed across Pygments versions.","solutions":["Check the available names via list(get_all_filters()) and use the exact name.","Correct the typo (e.g. 'codetags' is the built-in name, not 'codetag').","Install the plugin package that provides the filter, or implement a custom filter via @simplefilter."],"exampleFix":"# before\nfrom pygments.filters import get_filter_by_name\nf = get_filter_by_name('codetag')  # ClassNotFound\n\n# after\nfrom pygments.filters import get_all_filters\nassert 'codetags' in get_all_filters()\nf = get_filter_by_name('codetags')","handlingStrategy":"validation","validationCode":"from pygments.filters import find_filter_class, get_all_filters\nif filtername not in get_all_filters():\n    raise ValueError(f'unknown filter {filtername!r}; available: {sorted(get_all_filters())}')\nget_filter_by_name(filtername)","typeGuard":"def filter_exists(name: str) -> bool:\n    from pygments.filters import find_filter_class\n    return find_filter_class(name) is not None","tryCatchPattern":"try:\n    f = get_filter_by_name(name)\nexcept ClassNotFound as e:\n    if 'filter' in str(e) and 'not found' in str(e):\n        # pick a default or list available filters\n        from pygments.filters import get_all_filters\n        raise SystemExit(f'choose from {sorted(get_all_filters())}')\n    raise","preventionTips":["List names with get_all_filters() before referencing one.","Install any plugin packages whose filters you depend on."],"tags":["python","pygments","filter","lookup"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}