charmbracelet/gum · error

unable to create renderer: %w

Error message

unable to create renderer: %w

What it means

gum format's `code` handler builds a glamour (markdown terminal renderer) with environment-driven styling (`WithEnvironmentConfig`) and word wrap 0. If `glamour.NewTermRenderer` fails, the error is wrapped as `unable to create renderer: %w`. Failure here means glamour could not construct its renderer, typically due to bad style configuration discovered at construction time.

Source

Thrown at format/formats.go:19

//nolint
package format

import (
	"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)

View on GitHub (pinned to 4d089f9550)

Solutions

  1. Unset `GLAMOUR_STYLE` or set it to a valid built-in: ascii, dark, light, pink, DRACULA, NO_COLOR, or a valid JSON style path.
  2. Validate the custom style JSON against glamour's Style schema (ansi style spec).
  3. Fix file permissions on the referenced style file.
  4. Upgrade gum/glamour if the configured style name was removed in a newer version.

Example fix

// before
export GLAMOUR_STYLE=darkk // invalid style name
 gum format -t code file.go // unable to create renderer
// after
export GLAMOUR_STYLE=dark
 gum format -t code file.go
Defensive patterns

Strategy: validation

Validate before calling

if [ -n "$GLAMOUR_STYLE" ]; then
  case "$GLAMOUR_STYLE" in
    ascii|dark|light|pink|dracula|DRACULA|notty|NO_COLOR) ;;
    *) [ -r "$GLAMOUR_STYLE" ] || { echo "invalid GLAMOUR_STYLE: $GLAMOUR_STYLE" >&2; unset GLAMOUR_STYLE; } ;;
  esac
fi

Try / catch

if ! out=$(gum format -t code "$src"); then
  echo "renderer creation failed: $out — check GLAMOUR_STYLE" >&2
  unset GLAMOUR_STYLE
  out=$(gum format -t code "$src")
fi

Prevention

When it happens

Trigger: A `GLAMOUR_STYLE` environment variable names a style that cannot be loaded (unknown name, unreadable/invalid JSON style file), or glamour's style parsing returns an error during NewTermRenderer.

Common situations: Users setting GLAMOUR_STYLE to a custom JSON file with schema errors; typos like `GLAMOUR_STYLE=darkk`; environments where the default style definitions are missing from the installed version.

Related errors


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