charmbracelet/glow · error

unable to create renderer: %w

Error message

unable to create renderer: %w

What it means

executeCLI builds the renderer with glamour.NewTermRenderer, passing the resolved style via utils.GlamourStyle (glamour.WithStylePath for non-auto styles), word wrap width, base URL, and preserved newlines. Construction fails when the style cannot be loaded or parsed - most commonly a custom style JSON (-s ./mystyle.json) with invalid JSON or an invalid style structure. Built-in styles essentially never fail here.

Source

Thrown at main.go:300

	// render
	var baseURL string
	u, err := url.ParseRequestURI(src.URL)
	if err == nil {
		u.Path = filepath.Dir(u.Path)
		baseURL = u.String() + "/"
	}

	isCode := !utils.IsMarkdownFile(src.URL)

	// initialize glamour
	r, err := glamour.NewTermRenderer(
		utils.GlamourStyle(style, isCode),
		glamour.WithWordWrap(int(width)), //nolint:gosec
		glamour.WithBaseURL(baseURL),
		glamour.WithPreservedNewLines(),
	)
	if err != nil {
		return fmt.Errorf("unable to create renderer: %w", err)
	}

	content := string(b)
	ext := filepath.Ext(src.URL)
	if isCode {
		content = utils.WrapCodeBlock(string(b), ext)
	}

	out, err := r.Render(content)
	if err != nil {
		return fmt.Errorf("unable to render markdown: %w", err)
	}

	// display
	switch {
	case pager || cmd.Flags().Changed("pager"):
		pagerCmd := os.Getenv("PAGER")
		if pagerCmd == "" {

View on GitHub (pinned to e3970c813d)

Solutions

  1. Validate the JSON syntax: jq . mystyle.json
  2. Compare the structure against glamour's default style JSON (colors like #875faf or ANSI numbers, keys like document, block_code, h1)
  3. Isolate by rendering with a built-in style: glow -s dark README.md
  4. Check the word-wrap width and base URL arguments if calling this API from your own code

Example fix

// before (mystyle.json - trailing comma makes invalid JSON)
{ "document": { "block_prefix": "\n", "block_suffix": "\n", } }

// after
{
  "document": {
    "block_prefix": "\n",
    "block_suffix": "\n"
  }
}
Defensive patterns

Strategy: validation

Validate before calling

func styleParses(path string) error {
	b, err := os.ReadFile(path)
	if err != nil { return err }
	var cfg ansi.StyleConfig
	return json.Unmarshal(b, &cfg)
}

Prevention

When it happens

Trigger: Custom style file with JSON syntax errors (trailing commas, comments, unescaped quotes); style with wrong structure (unknown keys or malformed values glamour rejects); style path pointing at a directory; glamour version mismatch expecting different style keys.

Common situations: Hand-edited style JSONs, style generators emitting invalid JSON, styles written for an older glamour version after upgrading glow, copying style files partially.

Related errors


AI-assisted analysis of charmbracelet/glow@e3970c813d (2026-08-15). Data as JSON: /api/errors/be7860ea50801000. Report an issue: GitHub.