mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-01 22:42:45 +02:00
Allow getJSON errors to be ignored
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 #7866
This commit is contained in:
@@ -23,6 +23,9 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gohugoio/hugo/common/constants"
|
||||
"github.com/gohugoio/hugo/common/loggers"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/gohugoio/hugo/cache/filecache"
|
||||
@@ -85,7 +88,7 @@ func (ns *Namespace) GetCSV(sep string, urlParts ...interface{}) (d [][]string,
|
||||
|
||||
err = ns.getResource(cache, unmarshal, req)
|
||||
if err != nil {
|
||||
ns.deps.Log.ERROR.Printf("Failed to get CSV resource %q: %s", url, err)
|
||||
ns.deps.Log.(loggers.IgnorableLogger).Errorsf(constants.ErrRemoteGetCSV, "Failed to get CSV resource %q: %s", url, err)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -117,7 +120,7 @@ func (ns *Namespace) GetJSON(urlParts ...interface{}) (interface{}, error) {
|
||||
|
||||
err = ns.getResource(cache, unmarshal, req)
|
||||
if err != nil {
|
||||
ns.deps.Log.ERROR.Printf("Failed to get JSON resource %q: %s", url, err)
|
||||
ns.deps.Log.(loggers.IgnorableLogger).Errorsf(constants.ErrRemoteGetJSON, "Failed to get JSON resource %q: %s", url, err)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
@@ -108,14 +108,14 @@ func TestGetCSV(t *testing.T) {
|
||||
got, err := ns.GetCSV(test.sep, test.url)
|
||||
|
||||
if _, ok := test.expect.(bool); ok {
|
||||
c.Assert(int(ns.deps.Log.ErrorCounter.Count()), qt.Equals, 1)
|
||||
c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 1)
|
||||
//c.Assert(err, msg, qt.Not(qt.IsNil))
|
||||
c.Assert(got, qt.IsNil)
|
||||
continue
|
||||
}
|
||||
|
||||
c.Assert(err, qt.IsNil, msg)
|
||||
c.Assert(int(ns.deps.Log.ErrorCounter.Count()), qt.Equals, 0)
|
||||
c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 0)
|
||||
c.Assert(got, qt.Not(qt.IsNil), msg)
|
||||
c.Assert(got, qt.DeepEquals, test.expect, msg)
|
||||
|
||||
@@ -198,12 +198,12 @@ func TestGetJSON(t *testing.T) {
|
||||
got, _ := ns.GetJSON(test.url)
|
||||
|
||||
if _, ok := test.expect.(bool); ok {
|
||||
c.Assert(int(ns.deps.Log.ErrorCounter.Count()), qt.Equals, 1)
|
||||
c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 1)
|
||||
//c.Assert(err, msg, qt.Not(qt.IsNil))
|
||||
continue
|
||||
}
|
||||
|
||||
c.Assert(int(ns.deps.Log.ErrorCounter.Count()), qt.Equals, 0, msg)
|
||||
c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 0, msg)
|
||||
c.Assert(got, qt.Not(qt.IsNil), msg)
|
||||
c.Assert(got, qt.DeepEquals, test.expect)
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ func (ns *Namespace) getRemote(cache *filecache.Cache, unmarshal func([]byte) (b
|
||||
var err error
|
||||
handled = true
|
||||
for i := 0; i <= resRetries; i++ {
|
||||
ns.deps.Log.INFO.Printf("Downloading: %s ...", url)
|
||||
ns.deps.Log.Infof("Downloading: %s ...", url)
|
||||
var res *http.Response
|
||||
res, err = ns.client.Do(req)
|
||||
if err != nil {
|
||||
@@ -75,8 +75,8 @@ func (ns *Namespace) getRemote(cache *filecache.Cache, unmarshal func([]byte) (b
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ns.deps.Log.INFO.Printf("Cannot read remote resource %s: %s", url, err)
|
||||
ns.deps.Log.INFO.Printf("Retry #%d for %s and sleeping for %s", i+1, url, resSleep)
|
||||
ns.deps.Log.Infof("Cannot read remote resource %s: %s", url, err)
|
||||
ns.deps.Log.Infof("Retry #%d for %s and sleeping for %s", i+1, url, resSleep)
|
||||
time.Sleep(resSleep)
|
||||
}
|
||||
|
||||
|
@@ -195,13 +195,13 @@ func newDeps(cfg config.Provider) *deps.Deps {
|
||||
}
|
||||
cfg.Set("allModules", modules.Modules{mod})
|
||||
|
||||
cs, err := helpers.NewContentSpec(cfg, loggers.NewErrorLogger(), afero.NewMemMapFs())
|
||||
logger := loggers.NewIgnorableLogger(loggers.NewErrorLogger(), "none")
|
||||
cs, err := helpers.NewContentSpec(cfg, logger, afero.NewMemMapFs())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fs := hugofs.NewMem(cfg)
|
||||
logger := loggers.NewErrorLogger()
|
||||
|
||||
p, err := helpers.NewPathSpec(fs, cfg, nil)
|
||||
if err != nil {
|
||||
@@ -219,7 +219,7 @@ func newDeps(cfg config.Provider) *deps.Deps {
|
||||
FileCaches: fileCaches,
|
||||
ContentSpec: cs,
|
||||
Log: logger,
|
||||
DistinctErrorLog: helpers.NewDistinctLogger(logger.ERROR),
|
||||
DistinctErrorLog: helpers.NewDistinctLogger(logger.Error()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -24,8 +24,8 @@ import (
|
||||
// New returns a new instance of the fmt-namespaced template functions.
|
||||
func New(d *deps.Deps) *Namespace {
|
||||
ns := &Namespace{
|
||||
errorLogger: helpers.NewDistinctLogger(d.Log.ERROR),
|
||||
warnLogger: helpers.NewDistinctLogger(d.Log.WARN),
|
||||
errorLogger: helpers.NewDistinctLogger(d.Log.Error()),
|
||||
warnLogger: helpers.NewDistinctLogger(d.Log.Warn()),
|
||||
}
|
||||
|
||||
d.BuildStartListeners.Add(func() {
|
||||
|
Reference in New Issue
Block a user