gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
76.27k stars 7.55k forks source link

Regression behavior on editing a shortcode file [error on hugo server v0.42.2, error+panic on hugo server v0.43+] #4965

Closed kaushalmodi closed 6 years ago

kaushalmodi commented 6 years ago

Hello,

I am not sure which this panic issue crept in, but I can consistently reproduce it on the latest hugo built from https://github.com/gohugoio/hugo/commit/75acff5f20d0d41ffa1ae20402001c7a82f077cb.

Steps to reproduce

git clone --recurse-submodules https://gitlab.com/kaushalmodi/kaushalmodi.gitlab.io.git scripter.co
cd scripter.co
hugo server --buildDrafts --buildFuture --navigateToChanged -p 1313   
# Modify themes/refined/layouts/shortcodes/figure.html and save it (you can simply add a newline or space and save)

Panic

Below shows that:

Probably useful information: I set disableFastRender = true in my site's config.toml.

km²~/hugo/:scripter.co> hugo server --buildDrafts --buildFuture --navigateToChanged -p 1313   

                   | EN
+------------------+-----+
  Pages            | 865
  Paginator pages  |   8
  Non-page files   |  16
  Static files     |  81
  Processed images |   0
  Aliases          |   4
  Sitemaps         |   1
  Cleaned          |   0

Total in 1147 ms
Watching for changes in /home/kmodi/hugo/scripter.co/{assets,content,data,layouts,static,themes}
Watching for config changes in /home/kmodi/hugo/scripter.co/config.toml
Watching for config changes in /home/kmodi/hugo/scripter.co/themes/refined/config.toml
Watching for config changes in /home/kmodi/hugo/scripter.co/themes/hugo-atom-feed/config.toml
Watching for config changes in /home/kmodi/hugo/scripter.co/themes/hugo-jf2/config.toml
Serving pages from memory
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop

Change detected, rebuilding site
2018-07-18 09:28:48.602 -0400
Source changed "/home/kmodi/hugo/scripter.co/content/bits/plantuml-version.md": WRITE
Total in 400 ms

Change detected, rebuilding site
2018-07-18 09:28:56.602 -0400
Template changed "/home/kmodi/hugo/scripter.co/themes/refined/layouts/shortcodes/figure.html": WRITE
ERROR 2018/07/18 09:28:56 Failed to render "_default/taxonomy.html": programming error: no mainPageOutput for "posts/hugo-leaf-and-branch-bundles/index.md"
ERROR 2018/07/18 09:28:56 Stack Trace:
goroutine 930 [running]:
github.com/gohugoio/hugo/hugolib.stackTrace(0x4b0, 0xefbc65, 0x17)
        /home/kmodi/go.apps/src/github.com/gohugoio/hugo/hugolib/page.go:280 +0x76
github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts.func1(0xc42a2df8a0, 0xc420272c00)
        /home/kmodi/go.apps/src/github.com/gohugoio/hugo/hugolib/site.go:1770 +0x135
panic(0xd7c3c0, 0xc429a0a960)
        /home/kmodi/go/src/runtime/panic.go:502 +0x229
text/template.errRecover(0xc42a2df790)
        /home/kmodi/go/src/text/template/exec.go:143 +0x1ba
panic(0xd7c3c0, 0xc429a0a960)
        /home/kmodi/go/src/runtime/panic.go:502 +0x229
github.com/gohugoio/hugo/hugolib.(*Page).Render(0xc42278c000, 0xc429a0a940, 0x1, 0x1, 0x0, 0x0)
        /home/kmodi/go.apps/src/github.com/gohugoio/hugo/hugolib/page_output.go:159 +0x163
reflect.Value.call(0xea83e0, 0xc42278c000, 0xf613, 0xeae069, 0x4, 0xc4263d3100, 0x1, 0x1, 0xea2c80, 0x1, ...)
        /home/kmodi/go/src/reflect/value.go:447 +0x969
reflect.Value.Call(0xea83e0, 0xc42278c000, 0xf613, 0xc4263d3100, 0x1, 0x1, 0x108d6a0, 0xc425eb3380, 0xd7c3c0)
        /home/kmodi/go/src/reflect/value.go:308 +0xa4
text/template.(*state).evalCall(0xc42a2df548, 0xea83e0, 0xc42620a120, 0x196, 0xea83e0, 0xc42278c000, 0xf613, 0x108d4a0,
ERROR 2018/07/18 09:28:56 Failed to render "_default/taxonomy.html": programming error: no mainPageOutput for "posts/org-contribution-flowchart/index.md"
ERROR 2018/07/18 09:28:56 Stack Trace:
goroutine 930 [running]:
github.com/gohugoio/hugo/hugolib.stackTrace(0x4b0, 0xefbc65, 0x17)
        /home/kmodi/go.apps/src/github.com/gohugoio/hugo/hugolib/page.go:280 +0x76

# snipped

Full panic log

kaushalmodi commented 6 years ago

Here's the _default/taxonomy.html that seems to cause this panic, but not sure what's wrong in there. In any case, I should be getting a useful error.

{{ define "main" }}             <!-- List of all posts -->

<!-- http://microformats.org/wiki/h-feed -->
<section class="h-feed">
    <header>
        {{ partialCached "all-terms.html" . }}

        <!-- To complete the h-feed meta-data -->
        <data class="u-url" value="{{ .Permalink }}"></data>
        {{ partial "author.html" . }}

        <!-- If the page is /tags/foo/, .Data.Plural = "tags", .Data.Term = "foo"
             "%T" in the string retrieved from phrase map will be replaced with .Data.Term
             "%N" in the string retrieved from phrase map will be replaced with .Name
        -->
        {{ $term := .Data.Term }}
        {{ $phrase := (index .Site.Data.taxonomy.phrases .Data.Plural) | replaceRE "%T" (printf "‘%s’" $term) | replaceRE "%N" (printf "‘%s’" .Name) }}
        {{ $term_count := (len .Pages) }}
        <h1 class="p-name">{{ printf "Posts %s (%d)" $phrase $term_count }}</h1>
    </header>

    {{ range .Pages }}
        <!-- If the current page's $term is "foo", it replaces «li class="__foo__"»
             with «li class="active"».
             The "__<taxo>__" are special classes added to the taxo buttons in the
             taxo-buttons.html partial.
        -->
        {{ .Render "summary" | replaceRE (printf `(li class=")__%s__"` $term) `${1}active"` | safeHTML }}
    {{ end }}

    {{ partialCached "all-terms.html" . }}
</section>

{{ end }}
bep commented 6 years ago

Is this a new issue from Hugo?

kaushalmodi commented 6 years ago

I have never seen this before. I am guessing the recent change caused this. In the stack trace, the first trace is from page.go, and then site.go. Does it mean that the error originated from page.go? And I believe the recent changes heavily touched those 2 files?

kaushalmodi commented 6 years ago

OK, I just confirmed that this issue was on Hugo v0.44 too. I cannot reproduce this on v0.43 as my theme doesn't support that or older versions.. getting "Error: media type keys cannot contain any '+' chars. Valid example is "text/css"".


Update: See below, this regression was introduced in hugo v0.42.

kaushalmodi commented 6 years ago

@bep syncing up all theme components so that they work with a particular older hugo version is difficult. But I can narrow down the range of hugo versions that introduced this regression. I last modified my shortcodes on May 30. So this breakage probably happened in releases after that. So this issue could have been introduced in v0.42, v0.43 or v0.44.

I confirm this regression to have been introduced in v0.42.

kaushalmodi commented 6 years ago

OK, I finally confirm this regression to be introduced in v0.42.

Steps

In one terminal

git clone --recurse-submodules https://gitlab.com/kaushalmodi/kaushalmodi.gitlab.io.git scripter.co
cd scripter.co
git checkout builds-with-hugo-0-41
cd themes/refined
git checkout pre-theme-component-split
cd ../..
hugo server --buildDrafts --buildFuture --navigateToChanged -p 1313  

In another terminal

# cd to that cloned scripter.co dir
echo " " >> themes/refined/layouts/shortcodes/figure.html

Error on hugo v0.42.2 server (only when modifying that shortcode file)

The stacktrace/panic starts happening in v0.43 onwards.

Change detected, rebuilding site
2018-07-18 10:19:09.185 -0400
Template changed "/home/kmodi/temp/scripter.co/themes/refined/layouts/shortcodes/figure.html": WRITE
ERROR 2018/07/18 10:19:09 Failed to render "_default/taxonomy.html": programming error: no mainPageOutput for "posts/hugo-leaf-and-branch-bundles/index.md"
ERROR 2018/07/18 10:19:09 Failed to render "_default/taxonomy.html": programming error: no mainPageOutput for "posts/org-contribution-flowchart/index.md"
ERROR 2018/07/18 10:19:09 Failed to render "_default/taxonomy.html": programming error: no mainPageOutput for "posts/git-diff-minified-js-and-css/index.md"
ERROR 2018/07/18 10:19:09 Failed to render "_default/taxonomy.html": programming error: no mainPageOutput for "posts/accessing-devdocs-from-emacs/index.md"
ERROR 2018/07/18 10:19:09 Failed to render "_default/taxonomy.html": programming error: no mainPageOutput for "posts/convert-seconds-to-human-time/index.md"
ERROR 2018/07/18 10:19:09 Failed to render "_default/taxonomy.html": programming error: no mainPageOutput for "posts/microformats2/index.md"
ERROR 2018/07/18 10:19:09 Failed to render "_default/taxonomy.html": programming error: no mainPageOutput for "posts/narrowing-the-author-column-in-magit.md"
ERROR 2018/07/18 10:19:09 Failed to render "_default/taxonomy.html": programming error: no mainPageOutput for "notes/plantuml/index.md"
Total in 682 ms
ERROR 2018/07/18 10:19:09 Failed to rebuild site: logged 8 error(s)
kaushalmodi commented 6 years ago

I also narrowed down to the problematic line in the template:

{{ .Render "summary" | replaceRE (printf `(li class=")__%s__"` $term) `${1}active"` | safeHTML }}

The issue persists even if I replace:

{{ range .Pages }}
    {{ .Render "summary" | replaceRE (printf `(li class=")__%s__"` $term) `${1}active"` | safeHTML }}
{{ end }}

with:

{{ range .Pages }}
   {{ .Render "summary" }}
{{ end }}
kaushalmodi commented 6 years ago

Turns out that that "Failed to render .. programming error" error happens only for the posts where I am using the figure shortcode that I modified.

So in summary, hugo server fails on v0.42+ if one of the used shortcodes is modified.

kaushalmodi commented 6 years ago

From the commit message:

Fix potential server panic with drafts/future enabled

But I can recreate this issue even without draft/future: hugo server --navigateToChanged -p 1313.

Though, let me update the build and report back.

kaushalmodi commented 6 years ago

I confirm the fix, thanks!

bep commented 6 years ago

I have to reopen and apply a different fix for this. I didn't really understand the last one, and it had some side-effects ...

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.