{"record":{"id":"88e2353e95abf5c2","repo":"charmbracelet/glow","slug":"error-creating-glamour-renderer-w","errorCode":null,"errorMessage":"error creating glamour renderer: %w","messagePattern":"error creating glamour renderer: %w","errorType":"exception","errorClass":"errMsg","httpStatus":null,"severity":"error","filePath":"ui/pager.go","lineNumber":377,"sourceCode":"\t}\n\n\tisCode := !utils.IsMarkdownFile(m.currentDocument.Note)\n\twidth := max(0, min(int(m.common.cfg.GlamourMaxWidth), m.viewport.Width())) //nolint:gosec\n\tif isCode {\n\t\twidth = 0\n\t}\n\n\toptions := []glamour.TermRendererOption{\n\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","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/charmbracelet/glow/blob/e3970c813d93da1ea84edfca90c289d9afb82242/ui/pager.go#L359-L395","documentation":"Thrown while building the glamour.TermRenderer for the TUI pager (ui/pager.go:367-378). The style option comes from utils.GlamourStyle(cfg.GlamourStyle, isCode): built-in names and \"auto\" map to bundled styles, anything else becomes glamour.WithStylePath (or WithStylesFromJSONFile for code files, utils/utils.go:106). glamour.NewTermRenderer fails when that custom style cannot be loaded — missing name/path or a style file whose JSON is invalid. Note the config-file path is guarded by validateStyle (main.go:154-164), which stats the file but does not parse it, so malformed JSON slips past startup validation and only fails here.","triggerScenarios":"A hand-edited custom style JSON with a syntax error (passes os.Stat in validateStyle, fails at renderer construction); `style = \"solarized\"` in glow.yml when no such file or bundled style exists; GLAMOUR_STYLE env var pointing at a moved/deleted file; glamour upgrades renaming or dropping a previously bundled style.","commonSituations":"Custom themes kept as JSON files that later get truncated or corrupted; configs shared across machines where the style path differs; version drift between the glow that authored the config and the currently installed glamour styles; CI environments with stale GLAMOUR_STYLE exported.","solutions":["Verify the style file parses: `jq . ~/path/to/style.json` (or switch to a built-in: auto, dark, light, notty, dracula, tokyo-night, pink) via `--style` or glow.yml.","Confirm the path exists after ~ expansion (glow expands via utils.ExpandPath): `ls -l \"$HOME/styles/my-theme.json\"`.","Unset a stale environment override: `unset GLAMOUR_STYLE`.","If it persists, run `glow file.md` one-shot with the same style to reproduce outside the TUI and inspect the wrapped error from glamour."],"exampleFix":"# before (~/.config/glow/glow.yml): file exists but is malformed JSON\nstyle: ~/styles/my-theme.json\n\n# after: valid built-in style, or fix the JSON with `jq . ~/styles/my-theme.json`\nstyle: dark","handlingStrategy":"validation","validationCode":"func styleLoadable(style string) bool {\n\tif style == \"auto\" || styles.DefaultStyles[style] != nil {\n\t\treturn true\n\t}\n\tp := utils.ExpandPath(style)\n\tb, err := os.ReadFile(p)\n\treturn err == nil && json.Valid(b)\n}\n\n// before building the renderer:\nif !styleLoadable(m.common.cfg.GlamourStyle) {\n\tm.common.cfg.GlamourStyle = \"auto\"\n}","typeGuard":null,"tryCatchPattern":"r, err := glamour.NewTermRenderer(options...)\nif err != nil {\n\t// retry once with the default style instead of failing the pager\n\toptions[0] = glamour.WithStandardStyle(\"dark\")\n\tif r, err = glamour.NewTermRenderer(options...); err != nil {\n\t\treturn \"\", fmt.Errorf(\"error creating glamour renderer: %w\", err)\n\t}\n}","preventionTips":["Run `jq . <style.json>` on custom style files after every edit and in CI.","Keep custom styles under version control so corruption is detectable.","Know the built-in names (auto, dark, light, notty, dracula, tokyo-night, pink) before configuring a literal string.","Unset GLAMOUR_STYLE when testing style-related failures."],"tags":["glamour","styling","configuration","json","tui"],"backgroundTag":null,"analyzedSha":"e3970c813d93da1ea84edfca90c289d9afb82242","analyzedAt":"2026-08-15T22:50:54.304Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}