{"id":"7db72898fdaca455","repo":"pypa/pip","slug":"no-lexer-matching-the-text-found","errorCode":null,"errorMessage":"no lexer matching the text found","messagePattern":"no lexer matching the text found","errorType":"exception","errorClass":"ClassNotFound","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/lexers/__init__.py","lineNumber":339,"sourceCode":"\n    # try to get a vim modeline first\n    ft = get_filetype_from_buffer(_text)\n\n    if ft is not None:\n        try:\n            return get_lexer_by_name(ft, **options)\n        except ClassNotFound:\n            pass\n\n    best_lexer = [0.0, None]\n    for lexer in _iter_lexerclasses():\n        rv = lexer.analyse_text(_text)\n        if rv == 1.0:\n            return lexer(**options)\n        if rv > best_lexer[0]:\n            best_lexer[:] = (rv, lexer)\n    if not best_lexer[0] or best_lexer[1] is None:\n        raise ClassNotFound('no lexer matching the text found')\n    return best_lexer[1](**options)\n\n\nclass _automodule(types.ModuleType):\n    \"\"\"Automatically import lexers.\"\"\"\n\n    def __getattr__(self, name):\n        info = LEXERS.get(name)\n        if info:\n            _load_lexers(info[0])\n            cls = _lexer_cache[info[1]]\n            setattr(self, name, cls)\n            return cls\n        if name in COMPAT:\n            return getattr(self, COMPAT[name])\n        raise AttributeError(name)\n\n","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pygments/lexers/__init__.py#L321-L357","documentation":"Raised by guess_lexer when no lexer's analyse_text() returned a score above 0.0 for the input text. After checking vim modelines, every known lexer is scored; if the best score is 0.0 or no lexer is selected, this is raised.","triggerScenarios":"guess_lexer('') (empty), guess_lexer on very short/ambiguous text, or text in a language no installed lexer recognises.","commonSituations":"Auto-detecting a lexer for tiny snippets; binary/garbage content; niche language with no lexer; empty user input.","solutions":["Provide longer, more representative text so analyse_text can score it.","Specify the lexer explicitly with get_lexer_by_name.","Pre-validate that the text is non-empty and plausibly source code."],"exampleFix":"# before\nlex = guess_lexer('x')  # too short to score\n# after\nlex = get_lexer_by_name('python')  # explicit","handlingStrategy":"fallback","validationCode":"from pygments.lexers import guess_lexer, TextLexer\nfrom pygments.util import ClassNotFound\ndef safe_guess(text):\n    if not text or len(text.strip()) < 10:\n        return TextLexer()\n    try:\n        return guess_lexer(text)\n    except ClassNotFound:\n        return TextLexer()","typeGuard":null,"tryCatchPattern":"from pygments.util import ClassNotFound\nfrom pygments.lexers import guess_lexer, TextLexer\ntry:\n    lex = guess_lexer(text)\nexcept ClassNotFound:\n    lex = TextLexer()","preventionTips":["Require a minimum text length before guessing.","Always keep a TextLexer fallback for user-supplied content."],"tags":["pygments","lexer","guess","detection"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}