shithub: hugo

Download patch

ref: 7f3aab5ac283ecfc7029b680d4c0a34920e728c8
parent: 028b992611209b241b1f55def8d47f9188038dc3
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Thu Aug 15 06:56:49 EDT 2019

hugolib: Recover and log panics in content init

See #6210

--- a/hugolib/page__per_output.go
+++ b/hugolib/page__per_output.go
@@ -18,6 +18,7 @@
 	"context"
 	"fmt"
 	"html/template"
+	"runtime/debug"
 	"strings"
 	"sync"
 	"unicode/utf8"
@@ -65,8 +66,15 @@
 			f: f,
 		}
 
-		initContent := func() error {
-			var err error
+		initContent := func() (err error) {
+			defer func() {
+				// See https://github.com/gohugoio/hugo/issues/6210
+				if r := recover(); r != nil {
+					err = fmt.Errorf("%s", r)
+					p.s.Log.ERROR.Println("[BUG] Got panic:\n", string(debug.Stack()))
+				}
+			}()
+
 			var hasVariants bool
 
 			cp.contentPlaceholders, hasVariants, err = p.shortcodeState.renderShortcodesForPage(p, f)