{"record":{"id":"e34c7f6edb472a52","repo":"charmbracelet/glow","slug":"error-rendering-markdown-w","errorCode":null,"errorMessage":"error rendering markdown: %w","messagePattern":"error rendering markdown: %w","errorType":"exception","errorClass":"errMsg","httpStatus":null,"severity":"error","filePath":"ui/pager.go","lineNumber":386,"sourceCode":"\t\tutils.GlamourStyle(m.common.cfg.GlamourStyle, isCode),\n\t\tglamour.WithWordWrap(width),\n\t}\n\n\tif m.common.cfg.PreserveNewLines {\n\t\toptions = append(options, glamour.WithPreservedNewLines())\n\t}\n\tr, err := glamour.NewTermRenderer(options...)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error creating glamour renderer: %w\", err)\n\t}\n\n\tif isCode {\n\t\tmarkdown = utils.WrapCodeBlock(markdown, filepath.Ext(m.currentDocument.Note))\n\t}\n\n\tout, err := r.Render(markdown)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error rendering markdown: %w\", err)\n\t}\n\n\tif isCode {\n\t\tout = strings.TrimSpace(out)\n\t}\n\n\t// trim lines\n\tlines := strings.Split(out, \"\\n\")\n\n\tvar content strings.Builder\n\tfor i, s := range lines {\n\t\tif isCode || m.common.cfg.ShowLineNumbers {\n\t\t\tcontent.WriteString(m.common.styles.lineNumberStyle(fmt.Sprintf(\"%\"+fmt.Sprint(lineNumberWidth)+\"d\", i+1)))\n\t\t\tcontent.WriteString(trunc(s))\n\t\t} else {\n\t\t\tcontent.WriteString(s)\n\t\t}\n","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/charmbracelet/glow/blob/e3970c813d93da1ea84edfca90c289d9afb82242/ui/pager.go#L368-L404","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nout, err := r.Render(markdown)\nif err != nil {\n\treturn \"\", fmt.Errorf(\"error rendering markdown: %w\", err)\n}\n\n// after: keep the pager usable when glamour chokes on one document\nout, err := r.Render(markdown)\nif err != nil {\n\tlog.Warn(\"glamour render failed, showing raw markdown\", \"error\", err)\n\tout = markdown\n}","handlingStrategy":"fallback","validationCode":"if !utf8.ValidString(markdown) {\n\tmarkdown = strings.ToValidUTF8(markdown, \"\")\n}","typeGuard":null,"tryCatchPattern":"out, err := r.Render(markdown)\nif err != nil {\n\tlog.Warn(\"glamour render failed; falling back to raw markdown\", \"error\", err)\n\tout = markdown\n}","preventionTips":["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."],"tags":["glamour","markdown","rendering","utf-8","tui"],"backgroundTag":null,"analyzedSha":"e3970c813d93da1ea84edfca90c289d9afb82242","analyzedAt":"2026-08-15T22:50:54.304Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}