simplified buildSite & better error handling around it
authorspf13 <steve.francia@gmail.com>
Wed, 9 Oct 2013 23:06:47 +0000 (19:06 -0400)
committerspf13 <steve.francia@gmail.com>
Wed, 9 Oct 2013 23:14:26 +0000 (19:14 -0400)
commands/benchmark.go
commands/hugo.go
hugolib/node.go
utils/utils.go

index 8e6b43139cbb12fd91f8c3c8e29ecb05873d9563..010c1ed2b0854a19991d0488aab0418628a18d56 100644 (file)
@@ -46,6 +46,6 @@ func bench(cmd *cobra.Command, args []string) {
        defer pprof.StopCPUProfile()
 
        for i := 0; i < benchmarkTimes; i++ {
-               _, _ = buildSite()
+               _ = buildSite()
        }
 }
index 05187f90be5eec0187dd1b2deffb9d3e5a611b45..819b5c207fcb44987c1e5b12149856634981da48 100644 (file)
@@ -49,7 +49,7 @@ var Source, Destination, BaseUrl, CfgFile string
 func Execute() {
        AddCommands()
        Hugo := HugoCmd.ToCommander()
-       utils.CheckErrExit(Hugo.Execute())
+       utils.StopOnErr(Hugo.Execute())
 }
 
 func AddCommands() {
@@ -86,9 +86,7 @@ func InitializeConfig() {
 
 func build() {
        utils.CheckErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", Config.GetAbsPath(Config.PublishDir)))
-
-       _, e := buildSite()
-       utils.CheckErrExit(e)
+       utils.StopOnErr(buildSite())
 
        if BuildWatch {
                fmt.Println("Watching for changes in", Config.GetAbsPath(Config.ContentDir))
@@ -123,16 +121,16 @@ func getDirList() []string {
        return a
 }
 
-func buildSite() (site *hugolib.Site, err error) {
+func buildSite() (err error) {
        startTime := time.Now()
-       site = &hugolib.Site{Config: *Config}
+       site := &hugolib.Site{Config: *Config}
        err = site.Build()
        if err != nil {
                return
        }
        site.Stats()
        fmt.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds()))
-       return site, nil
+       return nil
 }
 
 func NewWatcher(port int) error {
@@ -181,9 +179,9 @@ func NewWatcher(port int) error {
 func watchChange(ev *fsnotify.FileEvent) {
        if strings.HasPrefix(ev.Name, Config.GetAbsPath(Config.StaticDir)) {
                fmt.Println("Static file changed, syncing\n")
-               copyStatic()
+               utils.CheckErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", Config.GetAbsPath(Config.PublishDir)))
        } else {
                fmt.Println("Change detected, rebuilding site\n")
-               buildSite()
+               utils.StopOnErr(buildSite())
        }
 }
index c0779261c60d88f860bd277e00c7e65144404b19..628675167a036d8c81ef16de692ca6cfb4ed973f 100644 (file)
@@ -19,9 +19,9 @@ import (
 )
 
 type Node struct {
-       RSSlink     template.HTML
-       Site        SiteInfo
-//     layout      string
+       RSSlink template.HTML
+       Site    SiteInfo
+       //      layout      string
        Data        map[string]interface{}
        Title       string
        Description string
index 641abfeb2bd949fb9df236f6400bf4dc5e566614..a79740c9a263826b1bb25786dea6f49458f50185 100644 (file)
@@ -14,7 +14,7 @@ func CheckErr(err error, s ...string) {
        }
 }
 
-func CheckErrExit(err error, s ...string) {
+func StopOnErr(err error, s ...string) {
        if err != nil {
                CheckErr(err, s...)
                os.Exit(-1)