google/closure-templates

Internal Soy Error when compiling Soy headers

mtheos opened this issue · 2 comments

Hello team!

I'm trying to run the Soy header compiler on example/simple.soy, and I'm running into the issue below.

Steps to reproduce:

java -cp target/soy-2022-10-26-with-dependencies.jar \
  com.google.template.soy.SoyHeaderCompiler \
  --output templateMeta.gz \
  --srcs examples/simple.soy

Stacktrace

INTERNAL SOY ERROR.
Please open an issue at https://github.com/google/closure-templates/issues with this stack trace and repro steps
java.util.NoSuchElementException: No value present
        at java.base/java.util.Optional.get(Optional.java:143)
        at com.google.template.soy.SoyFileSet.lambda$compileMinimallyForHeaders$14(SoyFileSet.java:1151)
        at com.google.template.soy.SoyFileSet.entryPoint(SoyFileSet.java:670)
        at com.google.template.soy.SoyFileSet.compileMinimallyForHeaders(SoyFileSet.java:1135)
        at com.google.template.soy.SoyHeaderCompiler.compile(SoyHeaderCompiler.java:83)
        at com.google.template.soy.AbstractSoyCompiler.doMain(AbstractSoyCompiler.java:337)
        at com.google.template.soy.AbstractSoyCompiler.run(AbstractSoyCompiler.java:228)
        at com.google.template.soy.AbstractSoyCompiler.runMain(AbstractSoyCompiler.java:221)
        at com.google.template.soy.SoyHeaderCompiler.main(SoyHeaderCompiler.java:172)

At face value, it appears that the CssRegistry is never instantiated and added to the sfsBuilder, but I have no idea if the registry is meant to be injected magically or if something has changed to make it go missing.

@Override
protected void compile(SoyFileSet.Builder sfsBuilder) throws IOException {
SoyFileSet.HeaderResult result = sfsBuilder.build().compileMinimallyForHeaders();
CompilationUnit unit =
TemplateMetadataSerializer.compilationUnitFromFileSet(

I've tried it with both Java 17 and 19, but I don't think that makes a difference. Likewise, I've also tried -SoyHeaderCompiler.jar to the same effect.

Thanks for your help! :)

Thank you for reporting this!

Does this fix the issue for you? Do you need us to make a new release with this fix?

Thanks @emspishak, the header compiler is working for me on master 🙂

We have worked around it by including all our soy templates as src so we don't need to compile the headers separately. This works for our needs but a new release would be ideal.