Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-10-21 12:17:48 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-10-22 10:09:29 +0300
commitfdfa4a5fe62232f65f1dd8d6fe0c500374228788 (patch)
treeb804e91506a7f3c58690c6fd774b28f95184d5dc /tpl
parent8cbe2bbfad6aa4de267921e24e166d4addf47040 (diff)
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
Diffstat (limited to 'tpl')
-rw-r--r--tpl/data/data.go7
-rw-r--r--tpl/data/data_test.go8
-rw-r--r--tpl/data/resources.go6
-rw-r--r--tpl/data/resources_test.go6
-rw-r--r--tpl/fmt/fmt.go4
5 files changed, 17 insertions, 14 deletions
diff --git a/tpl/data/data.go b/tpl/data/data.go
index f64ba0127..964844336 100644
--- a/tpl/data/data.go
+++ b/tpl/data/data.go
@@ -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
}
diff --git a/tpl/data/data_test.go b/tpl/data/data_test.go
index fa99006b2..e1839dd48 100644
--- a/tpl/data/data_test.go
+++ b/tpl/data/data_test.go
@@ -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)
}
diff --git a/tpl/data/resources.go b/tpl/data/resources.go
index 923d5946e..a7b8b3f49 100644
--- a/tpl/data/resources.go
+++ b/tpl/data/resources.go
@@ -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)
}
diff --git a/tpl/data/resources_test.go b/tpl/data/resources_test.go
index 11a9a8fc4..7350f82f1 100644
--- a/tpl/data/resources_test.go
+++ b/tpl/data/resources_test.go
@@ -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()),
}
}
diff --git a/tpl/fmt/fmt.go b/tpl/fmt/fmt.go
index 924d27a1d..780add0d1 100644
--- a/tpl/fmt/fmt.go
+++ b/tpl/fmt/fmt.go
@@ -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() {