{"record":{"id":"298db5767e466874","repo":"charmbracelet/gum","slug":"unable-to-render-w","errorCode":null,"errorMessage":"unable to render: %w","messagePattern":"unable to render: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"format/formats.go","lineNumber":23,"sourceCode":"\t\"bytes\"\n\t\"fmt\"\n\ttpl \"text/template\"\n\n\t\"charm.land/glamour/v2\"\n\t\"charm.land/lipgloss/v2\"\n)\n\nfunc code(input, language string) (string, error) {\n\trenderer, err := glamour.NewTermRenderer(\n\t\tglamour.WithEnvironmentConfig(),\n\t\tglamour.WithWordWrap(0),\n\t)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"unable to create renderer: %w\", err)\n\t}\n\toutput, err := renderer.Render(fmt.Sprintf(\"```%s\\n%s\\n```\", language, input))\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"unable to render: %w\", err)\n\t}\n\treturn output, nil\n}\n\nfunc emoji(input string) (string, error) {\n\trenderer, err := glamour.NewTermRenderer(\n\t\tglamour.WithEmoji(),\n\t)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"unable to create renderer: %w\", err)\n\t}\n\toutput, err := renderer.Render(input)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"unable to render: %w\", err)\n\t}\n\treturn output, nil\n}\n","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/charmbracelet/gum/blob/4d089f95507708a71f64dacfe7ca513219dd5267/format/formats.go#L5-L41","documentation":"After a renderer is constructed, gum format's `code` handler calls `renderer.Render` on the input wrapped in a fenced code block (```language ... ```). If glamour fails to parse or render the markdown, the error is wrapped as `unable to render: %w`. This indicates the content/format combination could not be rendered, not a setup problem.","triggerScenarios":"The rendered markdown (input wrapped in a code fence) trips a glamour parsing/rendering bug — often caused by pathological input (extremely long lines, invalid UTF-8 bytes, control characters) or a style whose element rules are malformed.","commonSituations":"Piping binary or non-UTF-8 data into `gum format -t code`; documents with broken encodings from Windows tooling; glamour version bugs with specific languages/inputs.","solutions":["Ensure the input is valid UTF-8: `iconv -f ... -t utf-8` or `dos2unix` before piping in.","Sanitize control characters/binary content out of the input.","Try rendering with a simpler style (unset GLAMOUR_STYLE) to rule out style-specific bugs.","Upgrade gum/glamour — several rendering panics/errors were fixed across releases; if it persists, file an issue with the offending input."],"exampleFix":"// before\ncat binary.out | gum format -t code // invalid bytes -> render error\n// after\niconv -f utf-8 -t utf-8 -c binary.out | gum format -t code","handlingStrategy":"fallback","validationCode":"iconv -f utf-8 -t utf-8 -c \"$file\" >/dev/null 2>&1 || { echo \"input is not valid UTF-8\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"if ! out=$(gum format -t code \"$src\"); then\n  echo \"render failed, falling back to plain text\" >&2\n  out=\"$src\"\nfi","preventionTips":["Ensure inputs are valid UTF-8 (iconv -c, dos2unix) before formatting.","Strip control characters/binary bytes from streamed content.","Fallback to raw text when rendering fails — rendering is cosmetic.","Keep gum/glamour updated; report reproducible render failures upstream."],"tags":["go","cli","glamour","markdown"],"backgroundTag":"markdown-render-failed","analyzedSha":"4d089f95507708a71f64dacfe7ca513219dd5267","analyzedAt":"2026-08-31T18:45:06.436Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}