{"id":"6a4ff78466388e3a","repo":"pypa/pip","slug":"no-formatter-found-for-file-name-fn-r","errorCode":null,"errorMessage":"no formatter found for file name {fn!r}","messagePattern":"no formatter found for file name (.+?)","errorType":"exception","errorClass":"ClassNotFound","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/formatters/__init__.py","lineNumber":137,"sourceCode":"    \"\"\"\n    Return a :class:`.Formatter` subclass instance that has a filename pattern\n    matching `fn`. The formatter is given the `options` at its instantiation.\n\n    Will raise :exc:`pygments.util.ClassNotFound` if no formatter for that filename\n    is found.\n    \"\"\"\n    fn = basename(fn)\n    for modname, name, _, filenames, _ in FORMATTERS.values():\n        for filename in filenames:\n            if _fn_matches(fn, filename):\n                if name not in _formatter_cache:\n                    _load_formatters(modname)\n                return _formatter_cache[name](**options)\n    for _name, cls in find_plugin_formatters():\n        for filename in cls.filenames:\n            if _fn_matches(fn, filename):\n                return cls(**options)\n    raise ClassNotFound(f\"no formatter found for file name {fn!r}\")\n\n\nclass _automodule(types.ModuleType):\n    \"\"\"Automatically import formatters.\"\"\"\n\n    def __getattr__(self, name):\n        info = FORMATTERS.get(name)\n        if info:\n            _load_formatters(info[0])\n            cls = _formatter_cache[info[1]]\n            setattr(self, name, cls)\n            return cls\n        raise AttributeError(name)\n\n\noldmod = sys.modules[__name__]\nnewmod = _automodule(__name__)\nnewmod.__dict__.update(oldmod.__dict__)","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pygments/formatters/__init__.py#L119-L155","documentation":"Raised by get_formatter_for_filename when no formatter's filename glob pattern (builtin or plugin) matches the basename of the supplied filename. The match uses fnmatch-style globs from each formatter's filenames attribute.","triggerScenarios":"get_formatter_for_filename('report.xyz') where .xyz isn't a registered extension, or a filename with no extension.","commonSituations":"Highlighting output for an unusual/custom file type; a filename whose extension isn't mapped to any output formatter; extension handled only by a plugin that isn't installed.","solutions":["Call get_formatter_by_name with an explicit formatter alias instead.","Register a plugin formatter whose filenames glob covers the extension.","List supported patterns via get_all_formatters() and each formatter's filenames."],"exampleFix":"# before\nfmt = get_formatter_for_filename('notes.xyz')\n# after\nfmt = get_formatter_by_name('html')","handlingStrategy":"fallback","validationCode":"from pygments.formatters import get_formatter_for_filename, get_formatter_by_name\nfrom pygments.util import ClassNotFound\ndef formatter_for(fn, fallback='html'):\n    try:\n        return get_formatter_for_filename(fn)\n    except ClassNotFound:\n        return get_formatter_by_name(fallback)","typeGuard":null,"tryCatchPattern":"from pygments.util import ClassNotFound\ntry:\n    fmt = get_formatter_for_filename(fn)\nexcept ClassNotFound:\n    fmt = get_formatter_by_name('html')","preventionTips":["Don't rely on filename-based formatter lookup for exotic extensions; map them explicitly."],"tags":["pygments","formatter","filename","lookup"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}