kovidgoyal/kitty · warning · ErrNoLexer
No lexer available for this format
Error message
No lexer available for this format
What it means
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.
Source
Thrown at tools/highlight/api.go:13
package highlight
import (
"errors"
"fmt"
"github.com/alecthomas/chroma/v2"
"github.com/kovidgoyal/kitty/tools/utils"
)
var _ = fmt.Print
var ErrNoLexer = errors.New("No lexer available for this format")
type StyleResolveData interface {
StyleName() string
UseLightColors() bool
SyntaxAliases() map[string]string
TextForPath(string) (string, error)
}
type Highlighter interface {
HighlightFile(path string, srd StyleResolveData) (highlighted_string string, err error)
Sanitize(string) string
}
func NewHighlighter(sanitize func(string) string) Highlighter {
if sanitize == nil {
sanitize = func(text string) string { return utils.ReplaceControlCodes(text, " ", "\n") }
}
return &highlighter{sanitize: sanitize, tokens_map: make(map[string][]chroma.Token)}View on GitHub (pinned to 6d5d0c4406)
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)
Example fix
// before
text, err := highlight.HighlightFile(f, ..., srd)
if err != nil { return err } // unknown extension aborts preview
// after
text, err := highlight.HighlightFile(f, ..., srd)
if errors.Is(err, highlight.ErrNoLexer) {
text, err = plainFallback(f) // render without highlighting
}
if err != nil { return err } Defensive patterns
Strategy: type-guard
Validate before calling
// pre-check lexer availability before highlighting
import "github.com/alecthomas/chroma/v2/lexers"
func hasLexer(path, format string, aliases map[string]string) bool {
if a, ok := aliases[format]; ok { format = a }
if format != "" && lexers.Get(format) != nil { return true }
return lexers.Match(path) != nil
} Type guard
func isNoLexer(err error) bool {
return errors.Is(err, highlight.ErrNoLexer)
} Try / catch
text, err := highlight.HighlightFile(...)
if errors.Is(err, highlight.ErrNoLexer) {
text = plainRender(...) // graceful degradation
err = nil
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Canceled by user
- Execute command
- No cache found and max cache age is negative
- Too much piped data
- This must be run as kitten ask
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/d9d0a8cfaeb2bfe9.
Report an issue: GitHub.