commands: Move time notification to after any build errors - hugo - [fork] hugo port for 9front
(HTM) git clone git@git.drkhsh.at/hugo.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
(DIR) commit 04dc469fbd78d9fe784829f2cba61c8cce982bdb
(DIR) parent 07919d1ccb01733f4c6c5952e59228cecc9b26c8
(HTM) Author: John Hollowell <johnahollowell@gmail.com>
Date: Mon, 5 Jul 2021 04:38:54 -0400
commands: Move time notification to after any build errors
This allows error parsers (VSCode problemMatchers) to use the time notification as bounds for detecting errors.
Closes #8403
Diffstat:
M commands/commands.go | 10 +++++++++-
M commands/hugo.go | 12 +++++++-----
M commands/server.go | 14 +++++++++++++-
3 files changed, 29 insertions(+), 7 deletions(-)
---
(DIR) diff --git a/commands/commands.go b/commands/commands.go
@@ -162,13 +162,21 @@ Complete documentation is available at http://gohugo.io/.`,
return nil
}
+ // prevent cobra printing error so it can be handled here (before the timeTrack prints)
+ cmd.SilenceErrors = true
+
c, err := initializeConfig(true, cc.buildWatch, &cc.hugoBuilderCommon, cc, cfgInit)
if err != nil {
+ cmd.PrintErrln("Error:", err.Error())
return err
}
cc.c = c
- return c.build()
+ err = c.build()
+ if err != nil {
+ cmd.PrintErrln("Error:", err.Error())
+ }
+ return err
},
})
(DIR) diff --git a/commands/hugo.go b/commands/hugo.go
@@ -539,7 +539,6 @@ func (c *commandeer) build() error {
}
func (c *commandeer) serverBuild() error {
- defer c.timeTrack(time.Now(), "Built")
stopProfiling, err := c.initProfiling()
if err != nil {
@@ -737,7 +736,6 @@ func (c *commandeer) handleBuildErr(err error, msg string) {
}
func (c *commandeer) rebuildSites(events []fsnotify.Event) error {
- defer c.timeTrack(time.Now(), "Total")
c.buildErr = nil
visited := c.visitedURLs.PeekAllSet()
@@ -1124,9 +1122,13 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher,
c.printChangeDetected("")
c.changeDetector.PrepareNew()
- if err := c.rebuildSites(dynamicEvents); err != nil {
- c.handleBuildErr(err, "Rebuild failed")
- }
+
+ func() {
+ defer c.timeTrack(time.Now(), "Total")
+ if err := c.rebuildSites(dynamicEvents); err != nil {
+ c.handleBuildErr(err, "Rebuild failed")
+ }
+ }()
if doLiveReload {
if len(partitionedEvents.ContentEvents) == 0 && len(partitionedEvents.AssetEvents) > 0 {
(DIR) diff --git a/commands/server.go b/commands/server.go
@@ -236,12 +236,24 @@ func (sc *serverCmd) server(cmd *cobra.Command, args []string) error {
jww.WARN.Println("memstats error:", err)
}
+ // silence errors in cobra so we can handle them here
+ cmd.SilenceErrors = true
+
c, err := initializeConfig(true, true, &sc.hugoBuilderCommon, sc, cfgInit)
if err != nil {
+ cmd.PrintErrln("Error:", err.Error())
return err
}
- if err := c.serverBuild(); err != nil {
+ err = func() error {
+ defer c.timeTrack(time.Now(), "Built")
+ err := c.serverBuild()
+ if err != nil {
+ cmd.PrintErrln("Error:", err.Error())
+ }
+ return err
+ }()
+ if err != nil {
return err
}