charmbracelet/gum · error

unable to render: %w

Error message

unable to render: %w

What it means

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.

Source

Thrown at format/formats.go:23

	"bytes"
	"fmt"
	tpl "text/template"

	"charm.land/glamour/v2"
	"charm.land/lipgloss/v2"
)

func code(input, language string) (string, error) {
	renderer, err := glamour.NewTermRenderer(
		glamour.WithEnvironmentConfig(),
		glamour.WithWordWrap(0),
	)
	if err != nil {
		return "", fmt.Errorf("unable to create renderer: %w", err)
	}
	output, err := renderer.Render(fmt.Sprintf("```%s\n%s\n```", language, input))
	if err != nil {
		return "", fmt.Errorf("unable to render: %w", err)
	}
	return output, nil
}

func emoji(input string) (string, error) {
	renderer, err := glamour.NewTermRenderer(
		glamour.WithEmoji(),
	)
	if err != nil {
		return "", fmt.Errorf("unable to create renderer: %w", err)
	}
	output, err := renderer.Render(input)
	if err != nil {
		return "", fmt.Errorf("unable to render: %w", err)
	}
	return output, nil
}

View on GitHub (pinned to 4d089f9550)

Solutions

  1. Ensure the input is valid UTF-8: `iconv -f ... -t utf-8` or `dos2unix` before piping in.
  2. Sanitize control characters/binary content out of the input.
  3. Try rendering with a simpler style (unset GLAMOUR_STYLE) to rule out style-specific bugs.
  4. Upgrade gum/glamour — several rendering panics/errors were fixed across releases; if it persists, file an issue with the offending input.

Example fix

// before
cat binary.out | gum format -t code // invalid bytes -> render error
// after
iconv -f utf-8 -t utf-8 -c binary.out | gum format -t code
Defensive patterns

Strategy: fallback

Validate before calling

iconv -f utf-8 -t utf-8 -c "$file" >/dev/null 2>&1 || { echo "input is not valid UTF-8" >&2; exit 1; }

Try / catch

if ! out=$(gum format -t code "$src"); then
  echo "render failed, falling back to plain text" >&2
  out="$src"
fi

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of charmbracelet/gum@4d089f9550 (2026-08-31). Data as JSON: /api/errors/298db5767e466874. Report an issue: GitHub.