{"record":{"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/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pygments/lexers/__init__.py#L78-L114","documentation":"Raised by find_lexer_class_by_name when the alias argument is falsy (empty string or None) before any lookup is attempted. An empty alias is treated as 'not found' immediately at lexers/__init__.py:95-96. Returns ClassNotFound. This guards against silent acceptance of an empty alias.","triggerScenarios":"Calling find_lexer_class_by_name('') or find_lexer_class_by_name(None). The 'if not _alias' check trips before the builtin/plugin search.","commonSituations":"Reading a language identifier from config that was left blank; variable unset before the call; whitespace-trimmed input that became empty.","solutions":["Validate that the alias is a non-empty string before calling.","Set a sensible default alias in your config rather than leaving it blank.","Strip and check: if not alias.strip(): raise your own error with context."],"exampleFix":"# before\nlexer_cls = find_lexer_class_by_name(user_input)\n# after\nalias = (user_input or '').strip()\nif not alias:\n    raise ValueError('language alias is required')\nlexer_cls = find_lexer_class_by_name(alias)","handlingStrategy":"validation","validationCode":"if not alias or not str(alias).strip():\n    raise ValueError('lexer alias must be a non-empty string')","typeGuard":"def is_nonempty_alias(alias) -> bool:\n    return bool(alias and str(alias).strip())","tryCatchPattern":"from pip._vendor.pygments.util import ClassNotFound\ntry:\n    cls = find_lexer_class_by_name(alias)\nexcept ClassNotFound:\n    cls = None","preventionTips":["Validate config-provided aliases are non-empty before lookup.","Default to a known alias like 'text'."],"tags":["python","pygments","lexer","validation","vendored"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}