summaryrefslogtreecommitdiffstats
path: root/common/herrors/errors.go
diff options
context:
space:
mode:
Diffstat (limited to 'common/herrors/errors.go')
-rw-r--r--common/herrors/errors.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/common/herrors/errors.go b/common/herrors/errors.go
index be98ceb39..1a6107050 100644
--- a/common/herrors/errors.go
+++ b/common/herrors/errors.go
@@ -19,6 +19,7 @@ import (
"fmt"
"io"
"os"
+ "runtime/debug"
_errors "github.com/pkg/errors"
)
@@ -46,6 +47,16 @@ func FprintStackTrace(w io.Writer, err error) {
}
}
+// Recover is a helper function that can be used to capture panics.
+// Put this at the top of a method/function that crashes in a template:
+// defer herrors.Recover()
+func Recover() {
+ if r := recover(); r != nil {
+ fmt.Println("stacktrace from panic: \n" + string(debug.Stack()))
+ }
+
+}
+
// ErrFeatureNotAvailable denotes that a feature is unavailable.
//
// We will, at least to begin with, make some Hugo features (SCSS with libsass) optional,