{"id":"847cde92d88f449f","repo":"gohugoio/hugo","slug":"failed-to-process-q-w","errorCode":null,"errorMessage":"failed to process %q: %w","messagePattern":"failed to process %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"publisher/publisher.go","lineNumber":108,"sourceCode":"}\n\n// Publish applies any relevant transformations and writes the file\n// to its destination, e.g. /public.\nfunc (p DestinationPublisher) Publish(d Descriptor) error {\n\tif d.TargetPath == \"\" {\n\t\treturn errors.New(\"Publish: must provide a TargetPath\")\n\t}\n\n\tsrc := d.Src\n\n\ttransformers := p.createTransformerChain(d)\n\n\tif len(transformers) != 0 {\n\t\tb := bp.GetBuffer()\n\t\tdefer bp.PutBuffer(b)\n\n\t\tif err := transformers.Apply(b, d.Src); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to process %q: %w\", d.TargetPath, err)\n\t\t}\n\n\t\t// This is now what we write to disk.\n\t\tsrc = b\n\t}\n\n\tf, err := helpers.OpenFileForWriting(p.fs, d.TargetPath)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer f.Close()\n\n\tvar w io.Writer = f\n\n\tif p.htmlElementsCollector != nil && d.OutputFormat.IsHTML {\n\t\tw = io.MultiWriter(w, newHTMLElementsCollectorWriter(p.htmlElementsCollector))\n\t}\n","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/publisher/publisher.go#L90-L126","documentation":"When Publish runs its transformer chain (minification, HTML element collection for build stats, live-reload injection, etc.) over the rendered content, any transformer failure is wrapped with the output's target path. It means the page rendered fine but a post-render output transformation failed for that specific file.","triggerScenarios":"transformers.Apply returning an error inside DestinationPublisher.Publish — most commonly the minifier (`minify = true` / --minify) choking on malformed HTML/JS/CSS/JSON/XML output, or the HTML elements collector processing invalid markup when writeStats/buildStats is enabled.","commonSituations":"Enabling --minify on a site whose templates emit invalid JSON or malformed HTML; raw content passed through without escaping breaking the minifier; templates generating an XML/JSON output format with syntax errors that only surface at minify time.","solutions":["Look at the wrapped inner error and the quoted target path — it names the exact output file and the real cause.","Build without --minify (or minify=false) to confirm the file itself is valid, then fix the template producing the malformed output.","For JSON/XML outputs, validate the generated file (e.g. jq, xmllint) and fix escaping in the template (use jsonify instead of hand-built JSON)."],"exampleFix":"<!-- before: hand-built JSON breaks the minifier -->\n{\"title\": \"{{ .Title }}\"}\n<!-- after -->\n{{ dict \"title\" .Title | jsonify }}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := pub.Publish(d); err != nil {\n    // wrapped: \"failed to process <path>: <cause>\"\n    return fmt.Errorf(\"publish %s: %w\", d.TargetPath, errors.Unwrap(err))\n}","preventionTips":["Inspect the wrapped cause with errors.Is/errors.As rather than string matching","The %q in the message names the failing output path — log it to locate the bad template/transform","Fail the build on this error; do not skip the file and continue"],"tags":["hugo","publisher","minify","output"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}