{"id":"dba28d89d930deb9","repo":"pypa/pip","slug":"no-lexer-for-alias-alias-r-found","errorCode":null,"errorMessage":"no lexer for alias {_alias!r} found","messagePattern":"no lexer for alias (.+?) found","errorType":"exception","errorClass":"ClassNotFound","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/lexers/__init__.py","lineNumber":96,"sourceCode":"    for cls in find_plugin_lexers():\n        if cls.name == name:\n            return cls\n\n\ndef find_lexer_class_by_name(_alias):\n    \"\"\"\n    Return the `Lexer` subclass that has `alias` in its aliases list, without\n    instantiating it.\n\n    Like `get_lexer_by_name`, but does not instantiate the class.\n\n    Will raise :exc:`pygments.util.ClassNotFound` if no lexer with that alias is\n    found.\n\n    .. versionadded:: 2.2\n    \"\"\"\n    if not _alias:\n        raise ClassNotFound(f'no lexer for alias {_alias!r} found')\n    # lookup builtin lexers\n    for module_name, name, aliases, _, _ in LEXERS.values():\n        if _alias.lower() in aliases:\n            if name not in _lexer_cache:\n                _load_lexers(module_name)\n            return _lexer_cache[name]\n    # continue with lexers from setuptools entrypoints\n    for cls in find_plugin_lexers():\n        if _alias.lower() in cls.aliases:\n            return cls\n    raise ClassNotFound(f'no lexer for alias {_alias!r} found')\n\n\ndef get_lexer_by_name(_alias, **options):\n    \"\"\"\n    Return an instance of a `Lexer` subclass that has `alias` in its\n    aliases list. The lexer is given the `options` at its\n    instantiation.","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pygments/lexers/__init__.py#L78-L114","documentation":"Raised by find_lexer_class_by_name when the alias argument is empty/falsy (None or empty string) before any lookup is attempted. It is the explicit empty-input guard at the top of that function.","triggerScenarios":"find_lexer_class_by_name(''), find_lexer_class_by_name(None), or passing a variable that was never assigned a language string.","commonSituations":"Reading the language from optional config that's absent; a CLI flag that wasn't supplied defaulting to None; upstream code passing through an unset value.","solutions":["Supply a non-empty, known alias string.","Default the variable to a safe alias like 'python' or 'text' before calling.","Validate the input is a non-empty string first."],"exampleFix":"# before\ncls = find_lexer_class_by_name(lang)  # lang is None\n# after\nlang = lang or 'text'\ncls = find_lexer_class_by_name(lang)","handlingStrategy":"validation","validationCode":"def valid_alias(a):\n    return isinstance(a, str) and bool(a.strip())\nif not valid_alias(alias):\n    raise ValueError('alias must be a non-empty string')","typeGuard":"def is_nonempty_alias(a):\n    return isinstance(a, str) and len(a.strip()) > 0","tryCatchPattern":null,"preventionTips":["Default optional language inputs to 'text'.","Validate non-empty string before lexer lookup."],"tags":["pygments","lexer","lookup","validation"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}