Skip to content

Commit 02ae632

Browse files
authored
Log STDERR of external renderer when it fails (go-gitea#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.
1 parent a3ab82e commit 02ae632

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

modules/markup/external/external.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package external
55

66
import (
7+
"bytes"
78
"fmt"
89
"io"
910
"os"
@@ -132,11 +133,13 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.
132133
if !p.IsInputFile {
133134
cmd.Stdin = input
134135
}
136+
var stderr bytes.Buffer
135137
cmd.Stdout = output
138+
cmd.Stderr = &stderr
136139
process.SetSysProcAttribute(cmd)
137140

138141
if err := cmd.Run(); err != nil {
139-
return fmt.Errorf("%s render run command %s %v failed: %w", p.Name(), commands[0], args, err)
142+
return fmt.Errorf("%s render run command %s %v failed: %w\nStderr: %s", p.Name(), commands[0], args, err, stderr.String())
140143
}
141144
return nil
142145
}

0 commit comments

Comments
 (0)