Better error handling when rendering error found when in watch mode

In watch mode it should continue to watch for changes, in any other mode it should exit with a -1 error code so can check for success when scripting
This commit is contained in:
spf13
2013-10-25 18:03:14 -04:00
parent 764abd2067
commit b580a25d1f
3 changed files with 26 additions and 6 deletions

View File

@@ -84,9 +84,13 @@ func InitializeConfig() {
}
}
func build() {
func build(watches ...bool) {
utils.CheckErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", Config.GetAbsPath(Config.PublishDir)))
utils.StopOnErr(buildSite())
watch := false
if len(watches) > 0 && watches[0] {
watch = true
}
utils.StopOnErr(buildSite(BuildWatch || watch))
if BuildWatch {
fmt.Println("Watching for changes in", Config.GetAbsPath(Config.ContentDir))
@@ -121,9 +125,12 @@ func getDirList() []string {
return a
}
func buildSite() (err error) {
func buildSite(watching ...bool) (err error) {
startTime := time.Now()
site := &hugolib.Site{Config: *Config}
if len(watching) > 0 && watching[0] {
site.RunMode.Watching = true
}
err = site.Build()
if err != nil {
return
@@ -185,7 +192,7 @@ func watchChange(ev *fsnotify.FileEvent) {
// Ignoring temp files created by editors (vim)
if !strings.HasSuffix(ev.Name, "~") && !strings.HasSuffix(ev.Name, ".swp") {
fmt.Println("Change detected, rebuilding site\n")
utils.StopOnErr(buildSite())
utils.StopOnErr(buildSite(true))
}
}
}