aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl/data
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2018-10-21 12:20:21 +0200
committerBjørn Erik Pedersen <[email protected]>2018-10-22 20:46:14 +0200
commitd1661b823af25c50d3bbe5366ea40a3cdd52e237 (patch)
treecd84d18229fb9c294ff1be56d7c0ce92a8f46761 /tpl/data
parent7930d2132a3c36c1aaca20f16f56978c84656b0a (diff)
downloadhugo-d1661b823af25c50d3bbe5366ea40a3cdd52e237.tar.gz
hugo-d1661b823af25c50d3bbe5366ea40a3cdd52e237.zip
hugolib: Continue the file context/line number errors work
See #5324
Diffstat (limited to 'tpl/data')
-rw-r--r--tpl/data/data.go24
-rw-r--r--tpl/data/data_test.go21
2 files changed, 14 insertions, 31 deletions
diff --git a/tpl/data/data.go b/tpl/data/data.go
index 3f87eda31..03fd27606 100644
--- a/tpl/data/data.go
+++ b/tpl/data/data.go
@@ -59,7 +59,7 @@ func (ns *Namespace) GetCSV(sep string, urlParts ...string) (d [][]string, err e
var req *http.Request
req, err = http.NewRequest("GET", url, nil)
if err != nil {
- return nil, _errors.Wrapf(err, "Failed to create request for getCSV for resource %s:", url)
+ return nil, _errors.Wrapf(err, "failed to create request for getCSV for resource %s", url)
}
req.Header.Add("Accept", "text/csv")
@@ -68,28 +68,22 @@ func (ns *Namespace) GetCSV(sep string, urlParts ...string) (d [][]string, err e
var c []byte
c, err = ns.getResource(req)
if err != nil {
- ns.deps.Log.ERROR.Printf("Failed to read CSV resource %q: %s", url, err)
- return nil, nil
+ return nil, _errors.Wrapf(err, "failed to read CSV resource %q", url)
}
if !bytes.Contains(c, []byte(sep)) {
- ns.deps.Log.ERROR.Printf("Cannot find separator %s in CSV for %s", sep, url)
- return nil, nil
+ return nil, _errors.Errorf("cannot find separator %s in CSV for %s", sep, url)
}
if d, err = parseCSV(c, sep); err != nil {
- ns.deps.Log.WARN.Printf("Failed to parse CSV file %s: %s", url, err)
+ err = _errors.Wrapf(err, "failed to parse CSV file %s", url)
+
clearCacheSleep(i, url)
continue
}
break
}
- if err != nil {
- ns.deps.Log.ERROR.Printf("Failed to read CSV resource %q: %s", url, err)
- return nil, nil
- }
-
return
}
@@ -103,7 +97,7 @@ func (ns *Namespace) GetJSON(urlParts ...string) (v interface{}, err error) {
var req *http.Request
req, err = http.NewRequest("GET", url, nil)
if err != nil {
- return nil, _errors.Wrapf(err, "Failed to create request for getJSON resource %s:", url)
+ return nil, _errors.Wrapf(err, "Failed to create request for getJSON resource %s", url)
}
req.Header.Add("Accept", "application/json")
@@ -111,10 +105,8 @@ func (ns *Namespace) GetJSON(urlParts ...string) (v interface{}, err error) {
var c []byte
c, err = ns.getResource(req)
if err != nil {
- ns.deps.Log.ERROR.Printf("Failed to get JSON resource %s: %s", url, err)
- return nil, nil
+ return nil, _errors.Wrapf(err, "failed to get getJSON resource %q", url)
}
-
err = json.Unmarshal(c, &v)
if err != nil {
ns.deps.Log.WARN.Printf("Cannot read JSON from resource %s: %s", url, err)
@@ -127,7 +119,7 @@ func (ns *Namespace) GetJSON(urlParts ...string) (v interface{}, err error) {
}
if err != nil {
- ns.deps.Log.ERROR.Printf("Failed to get JSON resource %s: %s", url, err)
+ return nil, _errors.Wrapf(err, "failed to get getJSON resource %q", url)
return nil, nil
}
return
diff --git a/tpl/data/data_test.go b/tpl/data/data_test.go
index 9ef969244..7a0640e95 100644
--- a/tpl/data/data_test.go
+++ b/tpl/data/data_test.go
@@ -21,8 +21,6 @@ import (
"strings"
"testing"
- jww "github.com/spf13/jwalterweatherman"
-
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -110,13 +108,13 @@ func TestGetCSV(t *testing.T) {
// Get on with it
got, err := ns.GetCSV(test.sep, test.url)
- require.NoError(t, err, msg)
-
if _, ok := test.expect.(bool); ok {
- require.Equal(t, 1, int(ns.deps.Log.ErrorCounter.Count()))
+ require.Error(t, err, msg)
require.Nil(t, got)
continue
}
+
+ require.NoError(t, err, msg)
require.Equal(t, 0, int(ns.deps.Log.ErrorCounter.Count()))
require.NotNil(t, got, msg)
@@ -140,12 +138,12 @@ func TestGetJSON(t *testing.T) {
{
`http://malformed/`,
`{gomeetup:["Sydney","San Francisco","Stockholm"]}`,
- jww.LevelError,
+ false,
},
{
`http://nofound/404`,
``,
- jww.LevelError,
+ false,
},
// Locals
{
@@ -156,7 +154,7 @@ func TestGetJSON(t *testing.T) {
{
"fail/no-file",
"",
- jww.LevelError,
+ false,
},
} {
@@ -198,13 +196,6 @@ func TestGetJSON(t *testing.T) {
continue
}
- if errLevel, ok := test.expect.(jww.Threshold); ok && errLevel >= jww.LevelError {
- logCount := ns.deps.Log.ErrorCounter.Count()
- require.True(t, logCount >= 1, fmt.Sprintf("got log count %d", logCount))
- continue
- }
- require.NoError(t, err, msg)
-
require.Equal(t, 0, int(ns.deps.Log.ErrorCounter.Count()), msg)
require.NotNil(t, got, msg)