charmbracelet/glow · error · errMsg
error rendering markdown: %w
Error message
error rendering markdown: %w
What it means
Thrown after the renderer exists, when r.Render(markdown) fails (ui/pager.go:384-387). This is the full markdown-to-ANSI pipeline: goldmark parsing, glamour's term rewriting and word wrapping, plus utils.WrapCodeBlock for non-markdown (code) files using the note's file extension. Failures bubble up from the goldmark parser or glamour's internal rendering, and are rare — when they fire, the input document or the active style is the culprit.
Source
Thrown at ui/pager.go:386
utils.GlamourStyle(m.common.cfg.GlamourStyle, isCode),
glamour.WithWordWrap(width),
}
if m.common.cfg.PreserveNewLines {
options = append(options, glamour.WithPreservedNewLines())
}
r, err := glamour.NewTermRenderer(options...)
if err != nil {
return "", fmt.Errorf("error creating glamour renderer: %w", err)
}
if isCode {
markdown = utils.WrapCodeBlock(markdown, filepath.Ext(m.currentDocument.Note))
}
out, err := r.Render(markdown)
if err != nil {
return "", fmt.Errorf("error rendering markdown: %w", err)
}
if isCode {
out = strings.TrimSpace(out)
}
// trim lines
lines := strings.Split(out, "\n")
var content strings.Builder
for i, s := range lines {
if isCode || m.common.cfg.ShowLineNumbers {
content.WriteString(m.common.styles.lineNumberStyle(fmt.Sprintf("%"+fmt.Sprint(lineNumberWidth)+"d", i+1)))
content.WriteString(trunc(s))
} else {
content.WriteString(s)
}
View on GitHub (pinned to e3970c813d)
Solutions
- Reproduce outside the pager: `glow <file>` one-shot with the same style to isolate TUI vs render.
- Rule out the style: retry with `--style=auto` (or light/dark).
- Sanitize input: check `file <note>` and strip invalid UTF-8 (`iconv -f UTF-8 -t UTF-8//IGNORE`).
- Bisect the document to find the offending construct and report a minimal repro to charmbracelet/glamour.
- As a code-level guard, degrade to raw markdown instead of failing the pager (see exampleFix).
Example fix
// before
out, err := r.Render(markdown)
if err != nil {
return "", fmt.Errorf("error rendering markdown: %w", err)
}
// after: keep the pager usable when glamour chokes on one document
out, err := r.Render(markdown)
if err != nil {
log.Warn("glamour render failed, showing raw markdown", "error", err)
out = markdown
} Defensive patterns
Strategy: fallback
Validate before calling
if !utf8.ValidString(markdown) {
markdown = strings.ToValidUTF8(markdown, "")
} Try / catch
out, err := r.Render(markdown)
if err != nil {
log.Warn("glamour render failed; falling back to raw markdown", "error", err)
out = markdown
} Prevention
- Validate UTF-8 of fetched or foreign content before paging it.
- Test suspect files with one-shot `glow file.md` before opening the TUI.
- Bisect large documents when a render failure appears, and keep a minimal repro for upstream.
- Pin the glamour version so render behavior is reproducible.
When it happens
Trigger: Paging a document with invalid UTF-8 bytes (e.g. fetched from a URL or a binary file misdetected as text); a custom style JSON that loads but breaks during rendering on specific constructs; pathological markdown (extreme nesting) choking the parser or reflow step; rendering a code file whose extension produces a WrapCodeBlock fence that trips goldmark.
Common situations: Browsing fetched READMEs or local code files in the glow TUI; files copied between systems with encoding damage; custom styles that pass loading but not rendering; glamour version changes altering render behavior.
Related errors
- unable to render markdown: %w
- unable to create renderer: %w
- error creating glamour renderer: %w
- could not load file: missing path
- error parsing config: %v
AI-assisted analysis of charmbracelet/glow@e3970c813d (2026-08-15).
Data as JSON: /api/errors/e34c7f6edb472a52.
Report an issue: GitHub.