diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-10-03 14:58:09 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-10-16 22:10:56 +0200 |
commit | 35fbfb19a173b01bc881f2bbc5d104136633a7ec (patch) | |
tree | 636d0d51fa262dc808eb3c5cc9cf92ad977a0c6a /i18n | |
parent | 3a3089121b852332b5744d1f566959c8cf93cef4 (diff) |
commands: Show server error info in browser
The main item in this commit is showing of errors with a file context when running `hugo server`.
This can be turned off: `hugo server --disableBrowserError` (can also be set in `config.toml`).
But to get there, the error handling in Hugo needed a revision. There are some items left TODO for commits soon to follow, most notable errors in content and config files.
Fixes #5284
Fixes #5290
See #5325
See #5324
Diffstat (limited to 'i18n')
-rw-r--r-- | i18n/i18n.go | 6 | ||||
-rw-r--r-- | i18n/i18n_test.go | 9 | ||||
-rw-r--r-- | i18n/translationProvider.go | 9 |
3 files changed, 10 insertions, 14 deletions
diff --git a/i18n/i18n.go b/i18n/i18n.go index 73417fb32..09f4b63f0 100644 --- a/i18n/i18n.go +++ b/i18n/i18n.go @@ -14,8 +14,10 @@ package i18n import ( + "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/helpers" + "github.com/nicksnyder/go-i18n/i18n/bundle" jww "github.com/spf13/jwalterweatherman" ) @@ -28,11 +30,11 @@ var ( type Translator struct { translateFuncs map[string]bundle.TranslateFunc cfg config.Provider - logger *jww.Notepad + logger *loggers.Logger } // NewTranslator creates a new Translator for the given language bundle and configuration. -func NewTranslator(b *bundle.Bundle, cfg config.Provider, logger *jww.Notepad) Translator { +func NewTranslator(b *bundle.Bundle, cfg config.Provider, logger *loggers.Logger) Translator { t := Translator{cfg: cfg, logger: logger, translateFuncs: make(map[string]bundle.TranslateFunc)} t.initFuncs(b) return t diff --git a/i18n/i18n_test.go b/i18n/i18n_test.go index 5075839ff..84b7384d0 100644 --- a/i18n/i18n_test.go +++ b/i18n/i18n_test.go @@ -19,24 +19,19 @@ import ( "github.com/gohugoio/hugo/tpl/tplimpl" + "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/langs" "github.com/spf13/afero" "github.com/gohugoio/hugo/deps" - "io/ioutil" - "os" - - "log" - "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/hugofs" - jww "github.com/spf13/jwalterweatherman" "github.com/spf13/viper" "github.com/stretchr/testify/require" ) -var logger = jww.NewNotepad(jww.LevelError, jww.LevelError, os.Stdout, ioutil.Discard, "", log.Ldate|log.Ltime) +var logger = loggers.NewErrorLogger() type i18nTest struct { data map[string][]byte diff --git a/i18n/translationProvider.go b/i18n/translationProvider.go index 5f90895aa..4e937c5a1 100644 --- a/i18n/translationProvider.go +++ b/i18n/translationProvider.go @@ -15,14 +15,13 @@ package i18n import ( "errors" - "fmt" - - "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/source" "github.com/nicksnyder/go-i18n/i18n/bundle" "github.com/nicksnyder/go-i18n/i18n/language" + _errors "github.com/pkg/errors" ) // TranslationProvider provides translation handling, i.e. loading @@ -82,12 +81,12 @@ func (tp *TranslationProvider) Update(d *deps.Deps) error { func addTranslationFile(bundle *bundle.Bundle, r source.ReadableFile) error { f, err := r.Open() if err != nil { - return fmt.Errorf("Failed to open translations file %q: %s", r.LogicalName(), err) + return _errors.Wrapf(err, "Failed to open translations file %q:", r.LogicalName()) } defer f.Close() err = bundle.ParseTranslationFileBytes(r.LogicalName(), helpers.ReaderToBytes(f)) if err != nil { - return fmt.Errorf("Failed to load translations in file %q: %s", r.LogicalName(), err) + return _errors.Wrapf(err, "Failed to load translations in file %q:", r.LogicalName()) } return nil } |