mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05: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 {
|
||||
// Channel for some "hard to get to" build errors
|
||||
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.
|
||||
|
@ -127,6 +129,7 @@ type globalErrHandler struct {
|
|||
func (e *globalErrHandler) SendError(err error) {
|
||||
if e.buildErrors != nil {
|
||||
select {
|
||||
case <-e.quit:
|
||||
case e.buildErrors <- err:
|
||||
default:
|
||||
}
|
||||
|
@ -137,10 +140,18 @@ func (e *globalErrHandler) SendError(err error) {
|
|||
}
|
||||
|
||||
func (e *globalErrHandler) StartErrorCollector() chan error {
|
||||
e.quit = make(chan struct{})
|
||||
e.buildErrors = make(chan error, 10)
|
||||
return e.buildErrors
|
||||
}
|
||||
|
||||
func (e *globalErrHandler) StopErrorCollector() {
|
||||
if e.buildErrors != nil {
|
||||
close(e.quit)
|
||||
close(e.buildErrors)
|
||||
}
|
||||
}
|
||||
|
||||
// Listeners represents an event listener.
|
||||
type Listeners struct {
|
||||
sync.Mutex
|
||||
|
|
|
@ -163,12 +163,7 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
|
|||
h.Log.Println(b.String())
|
||||
}
|
||||
|
||||
select {
|
||||
// Make sure the channel always gets something.
|
||||
case errCollector <- nil:
|
||||
default:
|
||||
}
|
||||
close(errCollector)
|
||||
h.StopErrorCollector()
|
||||
|
||||
err := <-errs
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue