mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-13 10:36:25 +00:00
Prevent the global error collector to panic when sending on closed channel
This commit is contained in:
parent
5596dc24a0
commit
9906c1ae52
2 changed files with 12 additions and 6 deletions
11
deps/deps.go
vendored
11
deps/deps.go
vendored
|
@ -119,6 +119,8 @@ type Deps struct {
|
||||||
type globalErrHandler struct {
|
type globalErrHandler struct {
|
||||||
// Channel for some "hard to get to" build errors
|
// Channel for some "hard to get to" build errors
|
||||||
buildErrors chan error
|
buildErrors chan error
|
||||||
|
// Used to signal that the build is done.
|
||||||
|
quit chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendErr sends the error on a channel to be handled later.
|
// SendErr sends the error on a channel to be handled later.
|
||||||
|
@ -127,6 +129,7 @@ type globalErrHandler struct {
|
||||||
func (e *globalErrHandler) SendError(err error) {
|
func (e *globalErrHandler) SendError(err error) {
|
||||||
if e.buildErrors != nil {
|
if e.buildErrors != nil {
|
||||||
select {
|
select {
|
||||||
|
case <-e.quit:
|
||||||
case e.buildErrors <- err:
|
case e.buildErrors <- err:
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
@ -137,10 +140,18 @@ func (e *globalErrHandler) SendError(err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *globalErrHandler) StartErrorCollector() chan error {
|
func (e *globalErrHandler) StartErrorCollector() chan error {
|
||||||
|
e.quit = make(chan struct{})
|
||||||
e.buildErrors = make(chan error, 10)
|
e.buildErrors = make(chan error, 10)
|
||||||
return e.buildErrors
|
return e.buildErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *globalErrHandler) StopErrorCollector() {
|
||||||
|
if e.buildErrors != nil {
|
||||||
|
close(e.quit)
|
||||||
|
close(e.buildErrors)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Listeners represents an event listener.
|
// Listeners represents an event listener.
|
||||||
type Listeners struct {
|
type Listeners struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
|
@ -163,12 +163,7 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
|
||||||
h.Log.Println(b.String())
|
h.Log.Println(b.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
h.StopErrorCollector()
|
||||||
// Make sure the channel always gets something.
|
|
||||||
case errCollector <- nil:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
close(errCollector)
|
|
||||||
|
|
||||||
err := <-errs
|
err := <-errs
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue