From 5d3237dddf9cff12c5bdc2936a66be71e85187cf Mon Sep 17 00:00:00 2001 From: Jonathan Tran Date: Fri, 13 Jan 2023 15:41:23 -0500 Subject: [PATCH] Log STDERR of external renderer when it fails (#22442) When using an external renderer, STDOUT is expected to be HTML. But anything written to STDERR is currently ignored. In cases where the renderer fails, I would like to log any error messages that the external program outputs to STDERR. --- modules/markup/external/external.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/markup/external/external.go b/modules/markup/external/external.go index 0eeb2d70a5f1..230cbccaac00 100644 --- a/modules/markup/external/external.go +++ b/modules/markup/external/external.go @@ -5,6 +5,7 @@ package external import ( + "bytes" "fmt" "io" "os" @@ -133,11 +134,13 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io. if !p.IsInputFile { cmd.Stdin = input } + var stderr bytes.Buffer cmd.Stdout = output + cmd.Stderr = &stderr process.SetSysProcAttribute(cmd) if err := cmd.Run(); err != nil { - return fmt.Errorf("%s render run command %s %v failed: %w", p.Name(), commands[0], args, err) + return fmt.Errorf("%s render run command %s %v failed: %w\nStderr: %s", p.Name(), commands[0], args, err, stderr.String()) } return nil }