{"record":{"id":"be7860ea50801000","repo":"charmbracelet/glow","slug":"unable-to-create-renderer-w","errorCode":null,"errorMessage":"unable to create renderer: %w","messagePattern":"unable to create renderer: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main.go","lineNumber":300,"sourceCode":"\t// render\n\tvar baseURL string\n\tu, err := url.ParseRequestURI(src.URL)\n\tif err == nil {\n\t\tu.Path = filepath.Dir(u.Path)\n\t\tbaseURL = u.String() + \"/\"\n\t}\n\n\tisCode := !utils.IsMarkdownFile(src.URL)\n\n\t// initialize glamour\n\tr, err := glamour.NewTermRenderer(\n\t\tutils.GlamourStyle(style, isCode),\n\t\tglamour.WithWordWrap(int(width)), //nolint:gosec\n\t\tglamour.WithBaseURL(baseURL),\n\t\tglamour.WithPreservedNewLines(),\n\t)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to create renderer: %w\", err)\n\t}\n\n\tcontent := string(b)\n\text := filepath.Ext(src.URL)\n\tif isCode {\n\t\tcontent = utils.WrapCodeBlock(string(b), ext)\n\t}\n\n\tout, err := r.Render(content)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to render markdown: %w\", err)\n\t}\n\n\t// display\n\tswitch {\n\tcase pager || cmd.Flags().Changed(\"pager\"):\n\t\tpagerCmd := os.Getenv(\"PAGER\")\n\t\tif pagerCmd == \"\" {","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/charmbracelet/glow/blob/e3970c813d93da1ea84edfca90c289d9afb82242/main.go#L282-L318","documentation":"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.","triggerScenarios":"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.","commonSituations":"Hand-edited style JSONs, style generators emitting invalid JSON, styles written for an older glamour version after upgrading glow, copying style files partially.","solutions":["Validate the JSON syntax: jq . mystyle.json","Compare the structure against glamour's default style JSON (colors like #875faf or ANSI numbers, keys like document, block_code, h1)","Isolate by rendering with a built-in style: glow -s dark README.md","Check the word-wrap width and base URL arguments if calling this API from your own code"],"exampleFix":"// before (mystyle.json - trailing comma makes invalid JSON)\n{ \"document\": { \"block_prefix\": \"\\n\", \"block_suffix\": \"\\n\", } }\n\n// after\n{\n  \"document\": {\n    \"block_prefix\": \"\\n\",\n    \"block_suffix\": \"\\n\"\n  }\n}","handlingStrategy":"validation","validationCode":"func styleParses(path string) error {\n\tb, err := os.ReadFile(path)\n\tif err != nil { return err }\n\tvar cfg ansi.StyleConfig\n\treturn json.Unmarshal(b, &cfg)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Lint custom style JSON with jq before shipping it","Validate the style parses before constructing the renderer","Keep a known-good built-in style as fallback"],"tags":["glamour","rendering","style","json","config"],"backgroundTag":null,"analyzedSha":"e3970c813d93da1ea84edfca90c289d9afb82242","analyzedAt":"2026-08-15T22:50:54.304Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}