Skip to content

Commit

Permalink
hugolib: Add some more details to the "paginator not supported" error
Browse files Browse the repository at this point in the history
See #11949
  • Loading branch information
bep committed Feb 1, 2024
1 parent 156f08d commit 1891d5e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions hugolib/page.go
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion hugolib/page__output.go
Expand Up @@ -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())
})
}

Expand Down
2 changes: 1 addition & 1 deletion hugolib/paginator_test.go
Expand Up @@ -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"`))
}

0 comments on commit 1891d5e

Please sign in to comment.