Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block inheritance only works if block.super is included #273

Closed
harlanji opened this issue Dec 14, 2021 · 10 comments
Closed

Block inheritance only works if block.super is included #273

harlanji opened this issue Dec 14, 2021 · 10 comments
Labels

Comments

@harlanji
Copy link

I copied my site theme and content from a cryogen-core 0.3.2 based project to a fresh lein new cryogen that uses 0.4.1. These use selmer 1.12.27 and 1.12.31 respectively.

I have a template that inherits from the default :post layout and overrides the content block. I hit an error in consume-block which I was able narrow down adding <!-- hack {{ block.super }} --> to my template. I was also able to resolve it by depending on versions as late as 1.12.28 directly in my project.clj.

Minimal template:

{% extends "/html/post.html" %}

{% block content %}
<!-- 
hack for selmer 1.12.29+:
 {{ block.super }}
/hack
-->
hi
{% endblock %}

If I run the build with latest selmer 1.12.31 it works, and then remove the commented section it fails.

The error:

                                      java.lang.Thread.run              Thread.java:  831
        java.util.concurrent.ThreadPoolExecutor$Worker.run  ThreadPoolExecutor.java:  630
         java.util.concurrent.ThreadPoolExecutor.runWorker  ThreadPoolExecutor.java: 1130
                                                       ...                               
                       clojure.core/binding-conveyor-fn/fn                 core.clj: 2036
                                                       ...                               
                                 hawk.core/catch-errors/fn                 core.clj:    8
                                        clojure.core/apply                 core.clj:  665
                                                       ...                               
                              hawk.core/process-handler/fn                 core.clj:   41
   cryogen-core.watcher/start-watcher-for-changes!/handler              watcher.clj:   51
                         cryogen-core.watcher/watch-assets              watcher.clj:   28
                                                       ...                               
cryogen-core.watcher/start-watcher-for-changes!/handler/fn              watcher.clj:   51
                                        clojure.core/apply                 core.clj:  665
                                                       ...                               
                    cryogen-core.watcher/start-watcher!/fn              watcher.clj:   58
                cryogen-core.compiler/compile-assets-timed             compiler.clj:  695
                cryogen-core.compiler/compile-assets-timed             compiler.clj:  696
                cryogen-core.compiler/compile-assets-timed             compiler.clj:  699
             cryogen-core.compiler/compile-assets-timed/fn             compiler.clj:  700
                      cryogen-core.compiler/compile-assets             compiler.clj:  672
                       cryogen-core.compiler/compile-posts             compiler.clj:  373
                         cryogen-core.compiler/render-file             compiler.clj:  336
                                                       ...                               
                                 selmer.parser/render-file               parser.clj:  122
                                 selmer.parser/render-file               parser.clj:  140
                                                       ...                               
                                       selmer.parser/parse               parser.clj:  329
                                       selmer.parser/parse               parser.clj:  357
                                  selmer.parser/parse-file               parser.clj:  327
                                                       ...                               
                selmer.template-parser/preprocess-template      template_parser.clj:  251
                selmer.template-parser/preprocess-template      template_parser.clj:  252
                      selmer.template-parser/read-template      template_parser.clj:  192
                   selmer.template-parser/read-template/fn      template_parser.clj:  226
                         selmer.template-parser/read-block      template_parser.clj:  116
                                                       ...                               
                      selmer.template-parser/consume-block      template_parser.clj:   52
                      selmer.template-parser/consume-block      template_parser.clj:   67

@yogthos yogthos added the bug label Dec 14, 2021
@yogthos
Copy link
Owner

yogthos commented Dec 14, 2021

I'm not actually able to reproduce this in a minimal project here. One thing I notice is that you have "/html/post.html" that should be a relative path"html/post.html".

@harlanji
Copy link
Author

harlanji commented Dec 14, 2021

Confirmed the cryogen-test example works with 1.12.45, and with Cryogen's version 1.12.31 as well. Pardon not trying latest prior.

More detailed steps to ensure we're in sync:

  • lein new cryogen ctest
  • added template file as themes/blue/html/post-b.html
  • updated content/md/posts/2014-03-10-first-post.md to have :layout :post-b.
  • lein run succeeds
  • remove {{ block.super }} from post-b.html
  • lein run fails

Wasn't able to solve it by removing the leading slash. To date cryogen's convention starts with a slash:

I modified a copy of cryogen-core to use selmer version 1.12.45, no luck still. Here's the modified lein deps :tree:

OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
 [clojure-complete "0.2.4" :exclusions [[org.clojure/clojure]]]
 [compojure "1.6.2"]
   [clout "2.2.1"]
     [instaparse "1.4.8" :exclusions [[org.clojure/clojure]]]
   [medley "1.3.0"]
   [org.clojure/tools.macro "0.1.5"]
   [ring/ring-codec "1.1.2"]
     [commons-codec "1.11"]
 [cryogen-core "0.4.1-new-selmer"]
   [camel-snake-kebab "0.4.2"]
   [cheshire "5.10.0"]
     [com.fasterxml.jackson.core/jackson-core "2.10.2"]
     [com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.10.2"]
     [com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.10.2"]
     [tigris "0.1.2"]
   [clj-rss "0.2.6"]
     [org.clojure/data.xml "0.2.0-alpha6"]
       [org.clojure/data.codec "0.1.0"]
   [clj-text-decoration "0.0.3"]
   [enlive "1.1.6"]
     [org.ccil.cowan.tagsoup/tagsoup "1.2.1"]
     [org.jsoup/jsoup "1.7.2"]
   [hawk "0.2.11"]
     [net.incongru.watchservice/barbary-watchservice "1.0"]
       [net.java.dev.jna/jna "3.2.2"]
   [io.aviso/pretty "0.1.37"]
   [me.raynes/fs "1.4.6"]
     [org.apache.commons/commons-compress "1.8"]
       [org.tukaani/xz "1.5"]
   [pandect "0.6.1"]
   [prismatic/schema "1.1.12"]
   [selmer "1.12.45"]
 [cryogen-flexmark "0.1.4"]
   [com.vladsch.flexmark/flexmark-ext-footnotes "0.60.2"]
   [com.vladsch.flexmark/flexmark-ext-gfm-strikethrough "0.60.2"]
   [com.vladsch.flexmark/flexmark-ext-superscript "0.60.2"]
   [com.vladsch.flexmark/flexmark-ext-tables "0.60.2"]
   [com.vladsch.flexmark/flexmark-util "0.60.2"]
     [com.vladsch.flexmark/flexmark-util-options "0.60.2"]
     [junit "4.12"]
       [org.hamcrest/hamcrest-core "1.3"]
     [org.jetbrains/annotations "15.0"]
   [com.vladsch.flexmark/flexmark "0.60.2"]
     [com.vladsch.flexmark/flexmark-util-ast "0.60.2"]
     [com.vladsch.flexmark/flexmark-util-builder "0.60.2"]
     [com.vladsch.flexmark/flexmark-util-collection "0.60.2"]
     [com.vladsch.flexmark/flexmark-util-data "0.60.2"]
     [com.vladsch.flexmark/flexmark-util-dependency "0.60.2"]
     [com.vladsch.flexmark/flexmark-util-format "0.60.2"]
     [com.vladsch.flexmark/flexmark-util-html "0.60.2"]
     [com.vladsch.flexmark/flexmark-util-misc "0.60.2"]
     [com.vladsch.flexmark/flexmark-util-sequence "0.60.2"]
     [com.vladsch.flexmark/flexmark-util-visitor "0.60.2"]
 [org.clojure/clojure "1.10.1"]
   [org.clojure/core.specs.alpha "0.2.44"]
   [org.clojure/spec.alpha "0.2.176"]
 [org.clojure/tools.nrepl "0.2.12" :exclusions [[org.clojure/clojure]]]
 [ring-server "0.5.0"]
   [ring-refresh "0.1.2"]
     [watchtower "0.1.1"]
   [ring "1.3.2"]
     [ring/ring-jetty-adapter "1.3.2"]
       [org.eclipse.jetty/jetty-server "7.6.13.v20130916"]
         [org.eclipse.jetty.orbit/javax.servlet "2.5.0.v201103041518"]
         [org.eclipse.jetty/jetty-continuation "7.6.13.v20130916"]
         [org.eclipse.jetty/jetty-http "7.6.13.v20130916"]
           [org.eclipse.jetty/jetty-io "7.6.13.v20130916"]
             [org.eclipse.jetty/jetty-util "7.6.13.v20130916"]
     [ring/ring-servlet "1.3.2"]
 [ring/ring-devel "1.8.2"]
   [clj-stacktrace "0.2.8"]
   [hiccup "1.0.5"]
   [ns-tracker "0.4.0"]
     [org.clojure/java.classpath "0.3.0"]
     [org.clojure/tools.namespace "0.2.11"]
   [ring/ring-core "1.8.2"]
     [commons-fileupload "1.4"]
     [commons-io "2.6"]
     [crypto-equality "1.0.0"]
     [crypto-random "1.2.0"]

Thanks.

@yogthos
Copy link
Owner

yogthos commented Dec 14, 2021

Interesting, not sure what happens in Cryogen to cause the issue. If we could replicate that in the standalone project that would help zero in on what's happening. Also, could you add the error message that'd be at the top of the trace. Might give a hint of what's tripping the parser up.

@harlanji
Copy link
Author

Pardon leaving the error out:

java.lang.NullPointerException: Cannot invoke "java.lang.StringBuilder.append(Object)" because "buf" is null

I've created a project reproduce it:

Full stack trace, also in repo as blocksuper-error.txt:

                            clojure.main.main            main.java:  40
                                          ...                          
                            clojure.main/main             main.clj: 616
                            clojure.main/main             main.clj: 664
                        clojure.main/null-opt             main.clj: 542
                      clojure.main/initialize             main.clj: 508
                        clojure.main/init-opt             main.clj: 477
                     clojure.main/load-script             main.clj: 475
                                          ...                          
                                 user/eval140            REPL Input    
                                          ...                          
                           cryogen.core/-main             core.clj:   7
   cryogen-core.compiler/compile-assets-timed         compiler.clj: 695
   cryogen-core.compiler/compile-assets-timed         compiler.clj: 696
   cryogen-core.compiler/compile-assets-timed         compiler.clj: 699
cryogen-core.compiler/compile-assets-timed/fn         compiler.clj: 700
         cryogen-core.compiler/compile-assets         compiler.clj: 672
          cryogen-core.compiler/compile-posts         compiler.clj: 373
            cryogen-core.compiler/render-file         compiler.clj: 336
                                          ...                          
                    selmer.parser/render-file           parser.clj: 122
                    selmer.parser/render-file           parser.clj: 140
                                          ...                          
                          selmer.parser/parse           parser.clj: 329
                          selmer.parser/parse           parser.clj: 357
                     selmer.parser/parse-file           parser.clj: 327
                                          ...                          
   selmer.template-parser/preprocess-template  template_parser.clj: 251
   selmer.template-parser/preprocess-template  template_parser.clj: 252
         selmer.template-parser/read-template  template_parser.clj: 192
      selmer.template-parser/read-template/fn  template_parser.clj: 226
            selmer.template-parser/read-block  template_parser.clj: 116
                                          ...                          
         selmer.template-parser/consume-block  template_parser.clj:  52
         selmer.template-parser/consume-block  template_parser.clj:  67
java.lang.NullPointerException: Cannot invoke "java.lang.StringBuilder.append(Object)" because "buf" is null

Thanks.

@harlanji
Copy link
Author

harlanji commented Dec 15, 2021

We're not providing the optional StringBuilder:

(do (consume-block rdr) blocks)

And later when we call consume-block we construct one inline:

(let [buf (doto (StringBuilder.) (.append block-tag)) has-super? (consume-block rdr buf blocks)]

StringBuilder.append returns a StringBuilder:

So I'm not sure the exact fix, maybe as easy as giving a new StringBuilder on line 116.

Pardon my if I've hung you up on this, thanks for being responsive. I can try this and report back if I don't hear anything before I get around to it. I'm not blocked since I can use the workaround, just wanted to get it posted so I didn't lose track.

Thanks.

@harlanji
Copy link
Author

Isolated it in the selmer-test project. Needs to have 3 layers of inheritance with an include in the middle layer.

Confirmed that it worked until 1.12.29. In my project I'd gotten another error about includes with that version where I mentioned it works until 1.12.28 above. If the fix isn't obvious I can go back and reproduce it.

base.html:

{% block content %}
{% endblock %}

post-content.html:

some content

post.html:

{% extends "html/base.html" %}

{% block content %}

{% include "html/post-content.html" %}

hello
{% endblock %}

foo.html

{% extends "html/post.html" %}

{% block content %}
hi
{% endblock %}

@yogthos
Copy link
Owner

yogthos commented Dec 15, 2021

Thanks for isolating the case, I'll have to take a look to see what the regression was between the commits there.

@yogthos
Copy link
Owner

yogthos commented Dec 16, 2021

Looks like the fix was simply to ensure that buf exists before appending. I pushed an fix, let me know if it works as expected on your end and I can push out an update. You can try it locally by cloning and running lein install from the repo. I bumped up the version to 1.12.46.

@yogthos
Copy link
Owner

yogthos commented Jan 5, 2022

fixed here

@yogthos yogthos closed this as completed Jan 5, 2022
@harlanji
Copy link
Author

harlanji commented Jan 7, 2022

I was able to add [selmer "1.12.49"] in project.clj and the Cryogen site built as expected. Thank you, sir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants