diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-10-21 12:20:21 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-10-22 20:46:14 +0200 |
commit | d1661b823af25c50d3bbe5366ea40a3cdd52e237 (patch) | |
tree | cd84d18229fb9c294ff1be56d7c0ce92a8f46761 /deps | |
parent | 7930d2132a3c36c1aaca20f16f56978c84656b0a (diff) | |
download | hugo-d1661b823af25c50d3bbe5366ea40a3cdd52e237.tar.gz hugo-d1661b823af25c50d3bbe5366ea40a3cdd52e237.zip |
hugolib: Continue the file context/line number errors work
See #5324
Diffstat (limited to 'deps')
-rw-r--r-- | deps/deps.go | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/deps/deps.go b/deps/deps.go index 1e2686421..db59ad212 100644 --- a/deps/deps.go +++ b/deps/deps.go @@ -5,7 +5,6 @@ import ( "time" "github.com/gohugoio/hugo/common/loggers" - "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/hugofs" @@ -16,6 +15,7 @@ import ( "github.com/gohugoio/hugo/resource" "github.com/gohugoio/hugo/source" "github.com/gohugoio/hugo/tpl" + jww "github.com/spf13/jwalterweatherman" ) // Deps holds dependencies used by many. @@ -73,6 +73,33 @@ type Deps struct { // BuildStartListeners will be notified before a build starts. BuildStartListeners *Listeners + + *globalErrHandler +} + +type globalErrHandler struct { + // Channel for some "hard to get to" build errors + buildErrors chan error +} + +// SendErr sends the error on a channel to be handled later. +// This can be used in situations where returning and aborting the current +// operation isn't practical. +func (e *globalErrHandler) SendError(err error) { + if e.buildErrors != nil { + select { + case e.buildErrors <- err: + default: + } + return + } + + jww.ERROR.Println(err) +} + +func (e *globalErrHandler) StartErrorCollector() chan error { + e.buildErrors = make(chan error, 10) + return e.buildErrors } // Listeners represents an event listener. @@ -194,6 +221,7 @@ func New(cfg DepsCfg) (*Deps, error) { Language: cfg.Language, BuildStartListeners: &Listeners{}, Timeout: time.Duration(timeoutms) * time.Millisecond, + globalErrHandler: &globalErrHandler{}, } if cfg.Cfg.GetBool("templateMetrics") { |