diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-10-03 15:58:09 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-10-16 23:10:56 +0300 |
commit | 35fbfb19a173b01bc881f2bbc5d104136633a7ec (patch) | |
tree | 636d0d51fa262dc808eb3c5cc9cf92ad977a0c6a /hugolib/testhelpers_test.go | |
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 'hugolib/testhelpers_test.go')
-rw-r--r-- | hugolib/testhelpers_test.go | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index 27edf3fdd..70c9263b3 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -14,7 +14,6 @@ import ( "github.com/gohugoio/hugo/langs" "github.com/sanity-io/litter" - jww "github.com/spf13/jwalterweatherman" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/deps" @@ -26,6 +25,7 @@ import ( "os" + "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/hugofs" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -38,7 +38,7 @@ type sitesBuilder struct { Fs *hugofs.Fs T testing.TB - logger *jww.Notepad + logger *loggers.Logger dumper litter.Options @@ -103,7 +103,7 @@ func (s *sitesBuilder) Running() *sitesBuilder { return s } -func (s *sitesBuilder) WithLogger(logger *jww.Notepad) *sitesBuilder { +func (s *sitesBuilder) WithLogger(logger *loggers.Logger) *sitesBuilder { s.logger = logger return s } @@ -312,6 +312,14 @@ func (s *sitesBuilder) writeFilePairs(folder string, filenameContent []string) * } func (s *sitesBuilder) CreateSites() *sitesBuilder { + if err := s.CreateSitesE(); err != nil { + s.Fatalf("Failed to create sites: %s", err) + } + + return s +} + +func (s *sitesBuilder) CreateSitesE() error { s.addDefaults() s.writeFilePairs("content", s.contentFilePairs) s.writeFilePairs("content", s.contentFilePairsAdded) @@ -325,7 +333,7 @@ func (s *sitesBuilder) CreateSites() *sitesBuilder { if s.Cfg == nil { cfg, _, err := LoadConfig(ConfigSourceDescriptor{Fs: s.Fs.Source, Filename: "config." + s.configFormat}) if err != nil { - s.Fatalf("Failed to load config: %s", err) + return err } // TODO(bep) /* expectedConfigs := 1 @@ -339,11 +347,19 @@ func (s *sitesBuilder) CreateSites() *sitesBuilder { sites, err := NewHugoSites(deps.DepsCfg{Fs: s.Fs, Cfg: s.Cfg, Logger: s.logger, Running: s.running}) if err != nil { - s.Fatalf("Failed to create sites: %s", err) + return err } s.H = sites - return s + return nil +} + +func (s *sitesBuilder) BuildE(cfg BuildCfg) error { + if s.H == nil { + s.CreateSites() + } + + return s.H.Build(cfg) } func (s *sitesBuilder) Build(cfg BuildCfg) *sitesBuilder { @@ -360,6 +376,7 @@ func (s *sitesBuilder) build(cfg BuildCfg, shouldFail bool) *sitesBuilder { } err := s.H.Build(cfg) + if err == nil { logErrorCount := s.H.NumLogErrors() if logErrorCount > 0 { @@ -639,13 +656,19 @@ func createWithTemplateFromNameValues(additionalTemplates ...string) func(templ } func buildSingleSite(t testing.TB, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site { - return buildSingleSiteExpected(t, false, depsCfg, buildCfg) + return buildSingleSiteExpected(t, false, false, depsCfg, buildCfg) } -func buildSingleSiteExpected(t testing.TB, expectBuildError bool, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site { +func buildSingleSiteExpected(t testing.TB, expectSiteInitEror, expectBuildError bool, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site { h, err := NewHugoSites(depsCfg) - require.NoError(t, err) + if expectSiteInitEror { + require.Error(t, err) + return nil + } else { + require.NoError(t, err) + } + require.Len(t, h.Sites, 1) if expectBuildError { |