From 1891d5e6b5575e3abb7e0f80c3fbce1670f9bd5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 1 Feb 2024 08:18:11 +0100 Subject: [PATCH] hugolib: Add some more details to the "paginator not supported" error See #11949 --- hugolib/page.go | 8 ++++++++ hugolib/page__output.go | 2 +- hugolib/paginator_test.go | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/hugolib/page.go b/hugolib/page.go index 822b7c021f4..10ecdcad2b8 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -553,6 +553,14 @@ func (p *pageState) wrapError(err error) error { return p.m.wrapError(err, p.s.h.SourceFs) } +func (p *pageState) getPageInfoForError() string { + s := fmt.Sprintf("kind: %q, path: %q", p.Kind(), p.Path()) + if p.File() != nil { + s += fmt.Sprintf(", file: %q", p.File().Filename()) + } + return s +} + func (p *pageState) getContentConverter() converter.Converter { var err error p.contentConverterInit.Do(func() { diff --git a/hugolib/page__output.go b/hugolib/page__output.go index 02956e87c68..9050766d1d0 100644 --- a/hugolib/page__output.go +++ b/hugolib/page__output.go @@ -47,7 +47,7 @@ func newPageOutput( paginatorProvider = pag } else { paginatorProvider = page.PaginatorNotSupportedFunc(func() error { - return fmt.Errorf("pagination not supported for pages of kind %q", ps.Kind()) + return fmt.Errorf("pagination not supported for this page: %s", ps.getPageInfoForError()) }) } diff --git a/hugolib/paginator_test.go b/hugolib/paginator_test.go index 919f532cac8..8075c0a5a6c 100644 --- a/hugolib/paginator_test.go +++ b/hugolib/paginator_test.go @@ -168,5 +168,5 @@ Paginator: {{ .Paginator }} ` b, err := TestE(t, files) b.Assert(err, qt.IsNotNil) - b.Assert(err.Error(), qt.Contains, `error calling Paginator: pagination not supported for pages of kind "page"`) + b.Assert(err.Error(), qt.Contains, `error calling Paginator: pagination not supported for this page: kind: "page", path: "/p1", file: `+filepath.FromSlash(`"/content/p1.md"`)) }