{"record":{"id":"f9ef33be42480b75","repo":"pypa/pip","slug":"no-lexer-for-filename-fn-r-found","errorCode":null,"errorMessage":"no lexer for filename {_fn!r} found","messagePattern":"no lexer for filename (.+?) found","errorType":"exception","errorClass":"ClassNotFound","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/lexers/__init__.py","lineNumber":227,"sourceCode":"        return matches[-1][0]\n\n\ndef get_lexer_for_filename(_fn, code=None, **options):\n    \"\"\"Get a lexer for a filename.\n\n    Return a `Lexer` subclass instance that has a filename pattern\n    matching `fn`. The lexer is given the `options` at its\n    instantiation.\n\n    Raise :exc:`pygments.util.ClassNotFound` if no lexer for that filename\n    is found.\n\n    If multiple lexers match the filename pattern, use their ``analyse_text()``\n    methods to figure out which one is more appropriate.\n    \"\"\"\n    res = find_lexer_class_for_filename(_fn, code)\n    if not res:\n        raise ClassNotFound(f'no lexer for filename {_fn!r} found')\n    return res(**options)\n\n\ndef get_lexer_for_mimetype(_mime, **options):\n    \"\"\"\n    Return a `Lexer` subclass instance that has `mime` in its mimetype\n    list. The lexer is given the `options` at its instantiation.\n\n    Will raise :exc:`pygments.util.ClassNotFound` if not lexer for that mimetype\n    is found.\n    \"\"\"\n    for modname, name, _, _, mimetypes in LEXERS.values():\n        if _mime in mimetypes:\n            if name not in _lexer_cache:\n                _load_lexers(modname)\n            return _lexer_cache[name](**options)\n    for cls in find_plugin_lexers():\n        if _mime in cls.mimetypes:","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pygments/lexers/__init__.py#L209-L245","documentation":"Raised by get_lexer_for_filename() as a ClassNotFound when find_lexer_class_for_filename(_fn, code) returns None (line 225-227), meaning no builtin lexer and no plugin lexer has a filename glob matching basename(_fn). It is the strict counterpart that throws instead of returning None.","triggerScenarios":"Calling get_lexer_for_filename('file.unknownext') where '.unknownext' matches no registered filename pattern in LEXERS or any plugin; passing a filename whose basename matches no glob in any lexer's filenames tuple.","commonSituations":"An unsupported or uncommon file extension (e.g., a proprietary config format); a custom file type with no registered lexer; the plugins providing the lexer are not installed in the environment; case-sensitivity issues where the pattern expects lowercase.","solutions":["Call find_lexer_class_for_filename(fn) first — it returns None instead of raising, so you can branch on a miss.","Map the extension to a known lexer alias manually and use get_lexer_by_name() instead (e.g., get_lexer_by_name('text') or 'ini').","Install or register a Pygments plugin / entry point that declares a filename glob covering your extension."],"exampleFix":"// before\nlexer = get_lexer_for_filename('config.xyz')\n\n// after\nfrom pygments.lexers import find_lexer_class_for_filename, get_lexer_by_name\nlexer_cls = find_lexer_class_for_filename('config.xyz')\nlexer = (lexer_cls or get_lexer_by_name('ini'))()","handlingStrategy":"fallback","validationCode":"from pygments.lexers import find_lexer_class_for_filename\ndef has_filename_lexer(fn):\n    return find_lexer_class_for_filename(fn) is not None","typeGuard":null,"tryCatchPattern":"from pygments.lexers import find_lexer_class_for_filename, get_lexer_by_name\nfrom pygments.util import ClassNotFound\ncls = find_lexer_class_for_filename(fn)\nlexer = cls() if cls else get_lexer_by_name('text')","preventionTips":["Prefer the non-raising find_lexer_class_for_filename() and branch on None.","Maintain an extension-to-alias fallback map for unsupported file types."],"tags":["pygments","lexer","filename","class-not-found"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}