{"record":{"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/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pygments/formatters/__init__.py#L119-L155","documentation":"Raised by get_formatter_for_filename when no built-in or plugin formatter's filename glob matches the given filename. Each formatter declares a 'filenames' tuple of glob patterns (e.g. '*.html'); if none match the basename, ClassNotFound is raised at __init__.py:137. Matching uses fnmatch translation.","triggerScenarios":"Calling get_formatter_for_filename('data.xyz') where no formatter claims the '.xyz' extension; passing a name with no extension; a custom extension not registered to any formatter.","commonSituations":"Highlighting an unusual file type with no registered formatter; missing extension; case mismatch (patterns are case-sensitive on some platforms); plugin for that extension not installed.","solutions":["Check get_all_formatters() filenames patterns and map your extension to one explicitly.","Use get_formatter_by_name with an explicit alias instead of filename guessing.","Install a plugin formatter that handles the extension."],"exampleFix":"# before\nfmt = get_formatter_for_filename('output.svgz')\n# after\nfmt = get_formatter_by_name('svg')","handlingStrategy":"try-catch","validationCode":"from pip._vendor.pygments.formatters import get_all_formatters\nglobs = [pat for cls in get_all_formatters() for pat in cls.filenames]\nimport fnmatch\nif not any(fnmatch.fnmatch(os.path.basename(fn), g) for g in globs):\n    raise ValueError(f'no formatter pattern matches {fn}')","typeGuard":"def filename_has_formatter(fn: str) -> bool:\n    from pip._vendor.pygments.formatters import get_all_formatters\n    import fnmatch, os\n    b = os.path.basename(fn)\n    return any(fnmatch.fnmatch(b, g) for cls in get_all_formatters() for g in cls.filenames)","tryCatchPattern":"from pip._vendor.pygments.util import ClassNotFound\ntry:\n    fmt = get_formatter_for_filename(fn)\nexcept ClassNotFound:\n    fmt = get_formatter_by_name('text')","preventionTips":["Prefer explicit get_formatter_by_name when you know the output format.","Maintain an extension-to-alias map for unusual file types."],"tags":["python","pygments","formatter","validation","vendored"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}