{"record":{"id":"d9d0a8cfaeb2bfe9","repo":"kovidgoyal/kitty","slug":"no-lexer-available-for-this-format","errorCode":null,"errorMessage":"No lexer available for this format","messagePattern":"No lexer available for this format","errorType":"error_code","errorClass":"ErrNoLexer","httpStatus":null,"severity":"warning","filePath":"tools/highlight/api.go","lineNumber":13,"sourceCode":"package highlight\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\n\t\"github.com/alecthomas/chroma/v2\"\n\t\"github.com/kovidgoyal/kitty/tools/utils\"\n)\n\nvar _ = fmt.Print\n\nvar ErrNoLexer = errors.New(\"No lexer available for this format\")\n\ntype StyleResolveData interface {\n\tStyleName() string\n\tUseLightColors() bool\n\tSyntaxAliases() map[string]string\n\tTextForPath(string) (string, error)\n}\n\ntype Highlighter interface {\n\tHighlightFile(path string, srd StyleResolveData) (highlighted_string string, err error)\n\tSanitize(string) string\n}\n\nfunc NewHighlighter(sanitize func(string) string) Highlighter {\n\tif sanitize == nil {\n\t\tsanitize = func(text string) string { return utils.ReplaceControlCodes(text, \"    \", \"\\n\") }\n\t}\n\treturn &highlighter{sanitize: sanitize, tokens_map: make(map[string][]chroma.Token)}","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/tools/highlight/api.go#L1-L31","documentation":"ErrNoLexer is returned by HighlightFile (and the highlight API) in tools/highlight when no chroma lexer can be resolved for the given file/format. The API uses chroma to syntax-highlight text; it first resolves a lexer by filename or format name (honoring SyntaxAliases() and TextForPath()); if chroma has no match, this sentinel error is returned so callers can fall back to plain, unhighlighted output.","triggerScenarios":"Calling HighlightFile with a file whose extension/first-line yields no chroma lexer, or a format string that isn't a registered lexer name and isn't covered by the StyleResolveData's syntax aliases; e.g. highlighting a file with an unknown extension like .xyz123.","commonSituations":"Previewing or echoing files with exotic or extensionless names in kitten tools (e.g. `kitten icat`-adjacent previews, `kitten diff` on unusual files); custom format strings that don't map to chroma lexer names; a syntax alias map missing an entry for a newly supported format.","solutions":["Handle ErrNoLexer explicitly and fall back to plain text rendering (errors.Is(err, highlight.ErrNoLexer))","Pass an explicit lexer/format (or add an entry to SyntaxAliases) so resolution succeeds","Verify the format string matches a chroma lexer name (see chroma's lexers registry)"],"exampleFix":"// before\ntext, err := highlight.HighlightFile(f, ..., srd)\nif err != nil { return err } // unknown extension aborts preview\n\n// after\ntext, err := highlight.HighlightFile(f, ..., srd)\nif errors.Is(err, highlight.ErrNoLexer) {\n    text, err = plainFallback(f) // render without highlighting\n}\nif err != nil { return err }","handlingStrategy":"type-guard","validationCode":"// pre-check lexer availability before highlighting\nimport \"github.com/alecthomas/chroma/v2/lexers\"\n\nfunc hasLexer(path, format string, aliases map[string]string) bool {\n    if a, ok := aliases[format]; ok { format = a }\n    if format != \"\" && lexers.Get(format) != nil { return true }\n    return lexers.Match(path) != nil\n}","typeGuard":"func isNoLexer(err error) bool {\n    return errors.Is(err, highlight.ErrNoLexer)\n}","tryCatchPattern":"text, err := highlight.HighlightFile(...)\nif errors.Is(err, highlight.ErrNoLexer) {\n    text = plainRender(...)  // graceful degradation\n    err = nil\n}","preventionTips":["Always implement a plain-text fallback for preview/highlight paths","Register aliases for custom formats via SyntaxResolveData.SyntaxAliases()","Pass explicit format hints for extensionless files"],"tags":["kitty","syntax-highlighting","chroma","sentinel-error","go"],"backgroundTag":"no-lexer-for-format","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}