Skip to content

Commit

Permalink
Allow getJSON errors to be ignored
Browse files Browse the repository at this point in the history
This change is mostly motivated to get a more stable CI build (we're building the Hugo site there, with Instagram and Twitter shortcodes sometimes failing).

Fixes gohugoio#7866
  • Loading branch information
bep committed Oct 21, 2020
1 parent 8cbe2bb commit ff10aee
Show file tree
Hide file tree
Showing 62 changed files with 366 additions and 265 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ script:
HUGO_TIMEOUT=30000 mage -v check;
fi
- mage -v hugo
- ./hugo -s docs/
- ./hugo --renderToMemory -s docs/
- HUGO_IGNOREERRORS=error-remote-getjson ./hugo -s docs/
- HUGO_IGNOREERRORS=error-remote-getjson ./hugo --renderToMemory -s docs/
- df -h
4 changes: 2 additions & 2 deletions commands/commandeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type commandeerHugoState struct {
type commandeer struct {
*commandeerHugoState

logger *loggers.Logger
logger loggers.Logger
serverConfig *config.Server

// Currently only set when in "fast render mode". But it seems to
Expand Down Expand Up @@ -415,7 +415,7 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error {
}
config.Set("cacheDir", cacheDir)

cfg.Logger.INFO.Println("Using config file:", config.ConfigFileUsed())
cfg.Logger.Infoln("Using config file:", config.ConfigFileUsed())

return nil

Expand Down
6 changes: 3 additions & 3 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (cc *hugoBuilderCommon) handleFlags(cmd *cobra.Command) {
_ = cmd.Flags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"})
}

func checkErr(logger *loggers.Logger, err error, s ...string) {
func checkErr(logger loggers.Logger, err error, s ...string) {
if err == nil {
return
}
Expand All @@ -331,7 +331,7 @@ func checkErr(logger *loggers.Logger, err error, s ...string) {
return
}
for _, message := range s {
logger.ERROR.Println(message)
logger.Println(message)
}
logger.ERROR.Println(err)
logger.Println(err)
}
10 changes: 5 additions & 5 deletions commands/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (cc *convertCmd) convertContents(format metadecoders.Format) error {

site := h.Sites[0]

site.Log.FEEDBACK.Println("processing", len(site.AllPages()), "content files")
site.Log.Println("processing", len(site.AllPages()), "content files")
for _, p := range site.AllPages() {
if err := cc.convertAndSavePage(p, site, format); err != nil {
return err
Expand All @@ -147,19 +147,19 @@ func (cc *convertCmd) convertAndSavePage(p page.Page, site *hugolib.Site, target

errMsg := fmt.Errorf("Error processing file %q", p.Path())

site.Log.INFO.Println("Attempting to convert", p.File().Filename())
site.Log.Infoln("Attempting to convert", p.File().Filename())

f := p.File()
file, err := f.FileInfo().Meta().Open()
if err != nil {
site.Log.ERROR.Println(errMsg)
site.Log.Errorln(errMsg)
file.Close()
return nil
}

pf, err := pageparser.ParseFrontMatterAndContent(file)
if err != nil {
site.Log.ERROR.Println(errMsg)
site.Log.Errorln(errMsg)
file.Close()
return err
}
Expand All @@ -179,7 +179,7 @@ func (cc *convertCmd) convertAndSavePage(p page.Page, site *hugolib.Site, target
var newContent bytes.Buffer
err = parser.InterfaceToFrontMatter(pf.FrontMatter, targetFormat, &newContent)
if err != nil {
site.Log.ERROR.Println(errMsg)
site.Log.Errorln(errMsg)
return err
}

Expand Down
6 changes: 3 additions & 3 deletions commands/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func newEnvCmd() *envCmd {
Long: `Print Hugo version and environment info. This is useful in Hugo bug reports.`,
RunE: func(cmd *cobra.Command, args []string) error {
printHugoVersion()
jww.FEEDBACK.Printf("GOOS=%q\n", runtime.GOOS)
jww.FEEDBACK.Printf("GOARCH=%q\n", runtime.GOARCH)
jww.FEEDBACK.Printf("GOVERSION=%q\n", runtime.Version())
jww.Printf("GOOS=%q\n", runtime.GOOS)
jww.Printf("GOARCH=%q\n", runtime.GOARCH)
jww.Printf("GOVERSION=%q\n", runtime.Version())

return nil
},
Expand Down
2 changes: 1 addition & 1 deletion commands/genautocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ or just source them in directly:
return err
}

jww.FEEDBACK.Println("Bash completion file for Hugo saved to", cc.autocompleteTarget)
jww.Println("Bash completion file for Hugo saved to", cc.autocompleteTarget)

return nil
},
Expand Down
6 changes: 3 additions & 3 deletions commands/gendoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ for rendering in Hugo.`,
cc.gendocdir += helpers.FilePathSeparator
}
if found, _ := helpers.Exists(cc.gendocdir, hugofs.Os); !found {
jww.FEEDBACK.Println("Directory", cc.gendocdir, "does not exist, creating...")
jww.Println("Directory", cc.gendocdir, "does not exist, creating...")
if err := hugofs.Os.MkdirAll(cc.gendocdir, 0777); err != nil {
return err
}
Expand All @@ -79,9 +79,9 @@ for rendering in Hugo.`,
return "/commands/" + strings.ToLower(base) + "/"
}

jww.FEEDBACK.Println("Generating Hugo command-line documentation in", cc.gendocdir, "...")
jww.Println("Generating Hugo command-line documentation in", cc.gendocdir, "...")
doc.GenMarkdownTreeCustom(cmd.Root(), cc.gendocdir, prepender, linkHandler)
jww.FEEDBACK.Println("Done.")
jww.Println("Done.")

return nil
},
Expand Down
6 changes: 3 additions & 3 deletions commands/genman.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ in the "man" directory under the current directory.`,
cc.genmandir += helpers.FilePathSeparator
}
if found, _ := helpers.Exists(cc.genmandir, hugofs.Os); !found {
jww.FEEDBACK.Println("Directory", cc.genmandir, "does not exist, creating...")
jww.Println("Directory", cc.genmandir, "does not exist, creating...")
if err := hugofs.Os.MkdirAll(cc.genmandir, 0777); err != nil {
return err
}
}
cmd.Root().DisableAutoGenTag = true

jww.FEEDBACK.Println("Generating Hugo man pages in", cc.genmandir, "...")
jww.Println("Generating Hugo man pages in", cc.genmandir, "...")
doc.GenManTree(cmd.Root(), header, cc.genmandir)

jww.FEEDBACK.Println("Done.")
jww.Println("Done.")

return nil
},
Expand Down
50 changes: 25 additions & 25 deletions commands/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func initializeConfig(mustHaveConfigFile, running bool,

}

func (c *commandeer) createLogger(cfg config.Provider, running bool) (*loggers.Logger, error) {
func (c *commandeer) createLogger(cfg config.Provider, running bool) (loggers.Logger, error) {
var (
logHandle = ioutil.Discard
logThreshold = jww.LevelWarn
Expand Down Expand Up @@ -374,12 +374,12 @@ func (c *commandeer) initMemProfile() {

f, err := os.Create(c.h.memprofile)
if err != nil {
c.logger.ERROR.Println("could not create memory profile: ", err)
c.logger.Println("could not create memory profile: ", err)
}
defer f.Close()
runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
c.logger.ERROR.Println("could not write memory profile: ", err)
c.logger.Println("could not write memory profile: ", err)
}
}

Expand Down Expand Up @@ -518,7 +518,7 @@ func (c *commandeer) build() error {
if createCounter, ok := c.destinationFs.(hugofs.DuplicatesReporter); ok {
dupes := createCounter.ReportDuplicates()
if dupes != "" {
c.logger.WARN.Println("Duplicate target paths:", dupes)
c.logger.Warnln("Duplicate target paths:", dupes)
}
}
}
Expand All @@ -532,8 +532,8 @@ func (c *commandeer) build() error {
baseWatchDir := c.Cfg.GetString("workingDir")
rootWatchDirs := getRootWatchDirsStr(baseWatchDir, watchDirs)

c.logger.FEEDBACK.Printf("Watching for changes in %s%s{%s}\n", baseWatchDir, helpers.FilePathSeparator, rootWatchDirs)
c.logger.FEEDBACK.Println("Press Ctrl+C to stop")
c.logger.Printf("Watching for changes in %s%s{%s}\n", baseWatchDir, helpers.FilePathSeparator, rootWatchDirs)
c.logger.Println("Press Ctrl+C to stop")
watcher, err := c.newWatcher(watchDirs...)
checkErr(c.Logger, err)
defer watcher.Close()
Expand Down Expand Up @@ -590,7 +590,7 @@ func (c *commandeer) doWithPublishDirs(f func(sourceFs *filesystems.SourceFilesy
staticFilesystems := c.hugo().BaseFs.SourceFilesystems.Static

if len(staticFilesystems) == 0 {
c.logger.INFO.Println("No static directories found to sync")
c.logger.Infoln("No static directories found to sync")
return langCount, nil
}

Expand Down Expand Up @@ -662,13 +662,13 @@ func (c *commandeer) copyStaticTo(sourceFs *filesystems.SourceFilesystem) (uint6
syncer.Delete = c.Cfg.GetBool("cleanDestinationDir")

if syncer.Delete {
c.logger.INFO.Println("removing all files from destination that don't exist in static dirs")
c.logger.Infoln("removing all files from destination that don't exist in static dirs")

syncer.DeleteFilter = func(f os.FileInfo) bool {
return f.IsDir() && strings.HasPrefix(f.Name(), ".")
}
}
c.logger.INFO.Println("syncing static files to", publishDir)
c.logger.Infoln("syncing static files to", publishDir)

// because we are using a baseFs (to get the union right).
// set sync src to root
Expand All @@ -689,7 +689,7 @@ func (c *commandeer) firstPathSpec() *helpers.PathSpec {

func (c *commandeer) timeTrack(start time.Time, name string) {
elapsed := time.Since(start)
c.logger.FEEDBACK.Printf("%s in %v ms", name, int(1000*elapsed.Seconds()))
c.logger.Printf("%s in %v ms", name, int(1000*elapsed.Seconds()))
}

// getDirList provides NewWatcher() with a list of directories to watch for changes.
Expand All @@ -698,7 +698,7 @@ func (c *commandeer) getDirList() ([]string, error) {

walkFn := func(path string, fi hugofs.FileMetaInfo, err error) error {
if err != nil {
c.logger.ERROR.Println("walker: ", err)
c.logger.Println("walker: ", err)
return nil
}

Expand All @@ -724,7 +724,7 @@ func (c *commandeer) getDirList() ([]string, error) {

w := hugofs.NewWalkway(hugofs.WalkwayConfig{Logger: c.logger, Info: fi, WalkFn: walkFn})
if err := w.Walk(); err != nil {
c.logger.ERROR.Println("walker: ", err)
c.logger.Println("walker: ", err)
}
}

Expand All @@ -740,8 +740,8 @@ func (c *commandeer) buildSites() (err error) {
func (c *commandeer) handleBuildErr(err error, msg string) {
c.buildErr = err

c.logger.ERROR.Print(msg + ":\n\n")
c.logger.ERROR.Println(helpers.FirstUpper(err.Error()))
c.logger.Print(msg + ":\n\n")
c.logger.Println(helpers.FirstUpper(err.Error()))
if !c.h.quiet && c.h.verbose {
herrors.PrintStackTraceFromErr(err)
}
Expand Down Expand Up @@ -822,13 +822,13 @@ func (c *commandeer) fullRebuild(changeType string) {
if !c.paused {
_, err := c.copyStatic()
if err != nil {
c.logger.ERROR.Println(err)
c.logger.Println(err)
return
}

err = c.buildSites()
if err != nil {
c.logger.ERROR.Println(err)
c.logger.Println(err)
} else if !c.h.buildWatch && !c.Cfg.GetBool("disableLiveReload") {
livereload.ForceRefresh()
}
Expand Down Expand Up @@ -862,7 +862,7 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
// Identifies changes to config (config.toml) files.
configSet := make(map[string]bool)

c.logger.FEEDBACK.Println("Watching for config changes in", strings.Join(c.configFiles, ", "))
c.logger.Println("Watching for config changes in", strings.Join(c.configFiles, ", "))
for _, configFile := range c.configFiles {
watcher.Add(configFile)
configSet[configFile] = true
Expand All @@ -879,7 +879,7 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
}
case err := <-watcher.Errors:
if err != nil {
c.logger.ERROR.Println("Error while watching:", err)
c.logger.Println("Error while watching:", err)
}
}
}
Expand All @@ -895,9 +895,9 @@ func (c *commandeer) printChangeDetected(typ string) {
}
msg += " detected, rebuilding site."

c.logger.FEEDBACK.Println(msg)
c.logger.Println(msg)
const layout = "2006-01-02 15:04:05.000 -0700"
c.logger.FEEDBACK.Println(time.Now().Format(layout))
c.logger.Println(time.Now().Format(layout))
}

const (
Expand Down Expand Up @@ -979,7 +979,7 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher,
return
}

c.logger.INFO.Println("Received System Events:", evs)
c.logger.Infoln("Received System Events:", evs)

staticEvents := []fsnotify.Event{}
dynamicEvents := []fsnotify.Event{}
Expand Down Expand Up @@ -1059,7 +1059,7 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher,

walkAdder := func(path string, f hugofs.FileMetaInfo, err error) error {
if f.IsDir() {
c.logger.FEEDBACK.Println("adding created directory to watchlist", path)
c.logger.Println("adding created directory to watchlist", path)
if err := watcher.Add(path); err != nil {
return err
}
Expand Down Expand Up @@ -1091,15 +1091,15 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher,
c.printChangeDetected("Static files")

if c.Cfg.GetBool("forceSyncStatic") {
c.logger.FEEDBACK.Printf("Syncing all static files\n")
c.logger.Printf("Syncing all static files\n")
_, err := c.copyStatic()
if err != nil {
c.logger.ERROR.Println("Error copying static files to publish dir:", err)
c.logger.Println("Error copying static files to publish dir:", err)
return
}
} else {
if err := staticSyncer.syncsStaticEvents(staticEvents); err != nil {
c.logger.ERROR.Println("Error syncing static files to publish dir:", err)
c.logger.Println("Error syncing static files to publish dir:", err)
return
}
}
Expand Down
10 changes: 5 additions & 5 deletions commands/import_jekyll.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (i *importCmd) importFromJekyll(cmd *cobra.Command, args []string) error {
return newUserError("path error:", args[1])
}

jww.INFO.Println("Import Jekyll from:", jekyllRoot, "to:", targetDir)
jww.Infoln("Import Jekyll from:", jekyllRoot, "to:", targetDir)

if strings.HasPrefix(filepath.Dir(targetDir), jekyllRoot) {
return newUserError("abort: target path should not be inside the Jekyll root")
Expand All @@ -113,7 +113,7 @@ func (i *importCmd) importFromJekyll(cmd *cobra.Command, args []string) error {
return newUserError(err)
}

jww.FEEDBACK.Println("Importing...")
jww.Println("Importing...")

fileCount := 0
callback := func(path string, fi hugofs.FileMetaInfo, err error) error {
Expand Down Expand Up @@ -155,10 +155,10 @@ func (i *importCmd) importFromJekyll(cmd *cobra.Command, args []string) error {
}
}

jww.FEEDBACK.Println("Congratulations!", fileCount, "post(s) imported!")
jww.FEEDBACK.Println("Now, start Hugo by yourself:\n" +
jww.Println("Congratulations!", fileCount, "post(s) imported!")
jww.Println("Now, start Hugo by yourself:\n" +
"$ git clone https://github.com/spf13/herring-cove.git " + args[1] + "/themes/herring-cove")
jww.FEEDBACK.Println("$ cd " + args[1] + "\n$ hugo server --theme=herring-cove")
jww.Println("$ cd " + args[1] + "\n$ hugo server --theme=herring-cove")

return nil
}
Expand Down
Loading

0 comments on commit ff10aee

Please sign in to comment.