apple / pkl

A configuration as code language with rich validation and tooling.
https://pkl-lang.org
Apache License 2.0
10.24k stars 275 forks source link

NullPointerException on chained module import and glob import #166

Open othompson2 opened 8 months ago

othompson2 commented 8 months ago

Run into an issue when I chain an @module import which in turn contains an import with a glob pattern. If I replace either the @module or glob pattern with a direct import the problem doesn't occur, so both seem to work independently just not when combined.


error:

java.lang.NullPointerException

–– Pkl Error ––
None (cause has no message)

6 | styling = import*("styles/*.pkl")
    ^^^^^^^
at section#styling (projectpackage://example.com/sections@0.0.1#/example/section.pkl)

106 | text = renderer.renderDocument(value)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (https://github.com/apple/pkl/blob/0.25.2/stdlib/base.pkl#L106)

Pkl 0.25.2 (macOS 14.1, native)

java.lang.NullPointerException
    at java.base@17.0.9/java.util.regex.Matcher.getTextLength(Matcher.java:1769)
    at java.base@17.0.9/java.util.regex.Matcher.reset(Matcher.java:415)
    at java.base@17.0.9/java.util.regex.Matcher.<init>(Matcher.java:252)
    at java.base@17.0.9/java.util.regex.Pattern.matcher(Pattern.java:1134)
    at org.pkl.core.util.IoUtils.isUriLike(IoUtils.java:67)
    at org.pkl.core.util.IoUtils.toUri(IoUtils.java:75)
    at org.pkl.core.util.IoUtils.createUri(IoUtils.java:81)
    at org.pkl.core.util.IoUtils.resolve(IoUtils.java:273)
    at org.pkl.core.runtime.ReaderBase.resolveUri(ReaderBase.java:74)
    at org.pkl.core.module.ModuleKeys$DependencyAwareModuleKey.resolveUri(ModuleKeys.java:559)
    at org.pkl.core.util.GlobResolver.resolveGlob(GlobResolver.java:519)
    at org.pkl.core.ast.expression.unary.ImportGlobNode.executeGeneric(ImportGlobNode.java:104)
    at org.pkl.core.ast.PklRootNode.executeBody(PklRootNode.java:41)
    at org.pkl.core.ast.MemberNode.executeBody(MemberNode.java:71)
    at org.pkl.core.ast.member.TypeCheckedPropertyNode.evalTypedObjectCached(TypeCheckedPropertyNode.java:55)
    at org.pkl.core.ast.member.TypeCheckedPropertyNodeGen.executeAndSpecialize(TypeCheckedPropertyNodeGen.java:135)
    at org.pkl.core.ast.member.TypeCheckedPropertyNodeGen.execute(TypeCheckedPropertyNodeGen.java:100)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:718)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:641)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:574)
    at org.graalvm.nativeimage.builder/com.oracle.svm.truffle.api.SubstrateOptimizedCallTarget.invokeCallBoundary(SubstrateOptimizedCallTarget.java:115)
    at com.oracle.svm.svm_enterprise/com.oracle.svm.enterprise.truffle.SubstrateEnterpriseOptimizedCallTarget.a(stripped:284)
    at com.oracle.svm.svm_enterprise/com.oracle.svm.enterprise.truffle.SubstrateEnterpriseOptimizedCallTarget.doInvoke(stripped:250)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callIndirect(OptimizedCallTarget.java:486)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.call(OptimizedCallTarget.java:467)
    at org.graalvm.truffle/com.oracle.truffle.api.nodes.IndirectCallNode$1.call(IndirectCallNode.java:91)
    at org.pkl.core.runtime.VmUtils.doReadMember(VmUtils.java:297)
    at org.pkl.core.runtime.VmUtils.doReadMember(VmUtils.java:210)
    at org.pkl.core.runtime.VmObject.force(VmObject.java:177)
    at org.pkl.core.runtime.VmObject.forceAndIterateMemberValues(VmObject.java:116)
    at org.pkl.core.stdlib.AbstractRenderer.visitTyped(AbstractRenderer.java:252)
    at org.pkl.core.runtime.VmTyped.accept(VmTyped.java:168)
    at org.pkl.core.runtime.VmValueVisitor.visit(VmValueVisitor.java:65)
    at org.pkl.core.stdlib.AbstractRenderer.visit(AbstractRenderer.java:126)
    at org.pkl.core.stdlib.base.JsonRendererNodes$JsonRenderer.visitProperty(JsonRendererNodes.java:230)
    at org.pkl.core.stdlib.AbstractRenderer.doVisitProperty(AbstractRenderer.java:195)
    at org.pkl.core.stdlib.AbstractRenderer.lambda$visitTyped$0(AbstractRenderer.java:256)
    at org.pkl.core.runtime.VmObject.lambda$iterateAlreadyForcedMemberValues$1(VmObject.java:132)
    at org.pkl.core.runtime.VmObject.iterateMembers(VmObject.java:148)
    at org.pkl.core.runtime.VmObject.iterateMembers(VmObject.java:141)
    at org.pkl.core.runtime.VmObject.iterateAlreadyForcedMemberValues(VmObject.java:124)
    at org.pkl.core.runtime.VmObject.forceAndIterateMemberValues(VmObject.java:117)
    at org.pkl.core.stdlib.AbstractRenderer.visitTyped(AbstractRenderer.java:252)
    at org.pkl.core.runtime.VmTyped.accept(VmTyped.java:168)
    at org.pkl.core.runtime.VmValueVisitor.visit(VmValueVisitor.java:65)
    at org.pkl.core.stdlib.AbstractRenderer.visit(AbstractRenderer.java:126)
    at org.pkl.core.stdlib.base.JsonRendererNodes$JsonRenderer.visitEntryValue(JsonRendererNodes.java:221)
    at org.pkl.core.stdlib.AbstractRenderer.doVisitEntry(AbstractRenderer.java:219)
    at org.pkl.core.stdlib.AbstractRenderer.visitMap(AbstractRenderer.java:375)
    at org.pkl.core.runtime.VmMap.accept(VmMap.java:235)
    at org.pkl.core.runtime.VmValueVisitor.visit(VmValueVisitor.java:65)
    at org.pkl.core.stdlib.AbstractRenderer.visit(AbstractRenderer.java:126)
    at org.pkl.core.stdlib.base.JsonRendererNodes$JsonRenderer.visitProperty(JsonRendererNodes.java:230)
    at org.pkl.core.stdlib.AbstractRenderer.doVisitProperty(AbstractRenderer.java:195)
    at org.pkl.core.stdlib.AbstractRenderer.lambda$visitTyped$0(AbstractRenderer.java:256)
    at org.pkl.core.runtime.VmObject.lambda$iterateAlreadyForcedMemberValues$1(VmObject.java:132)
    at org.pkl.core.runtime.VmObject.iterateMembers(VmObject.java:148)
    at org.pkl.core.runtime.VmObject.iterateMembers(VmObject.java:141)
    at org.pkl.core.runtime.VmObject.iterateAlreadyForcedMemberValues(VmObject.java:124)
    at org.pkl.core.runtime.VmObject.forceAndIterateMemberValues(VmObject.java:117)
    at org.pkl.core.stdlib.AbstractRenderer.visitTyped(AbstractRenderer.java:252)
    at org.pkl.core.runtime.VmTyped.accept(VmTyped.java:168)
    at org.pkl.core.runtime.VmValueVisitor.visit(VmValueVisitor.java:65)
    at org.pkl.core.stdlib.AbstractRenderer.visit(AbstractRenderer.java:126)
    at org.pkl.core.stdlib.base.JsonRendererNodes$JsonRenderer.visitDocument(JsonRendererNodes.java:73)
    at org.pkl.core.stdlib.AbstractRenderer.renderDocument(AbstractRenderer.java:101)
    at org.pkl.core.stdlib.base.JsonRendererNodes$renderDocument.eval(JsonRendererNodes.java:37)
    at org.pkl.core.stdlib.base.JsonRendererNodesFactory$renderDocumentNodeGen.executeAndSpecialize(JsonRendererNodesFactory.java:93)
    at org.pkl.core.stdlib.base.JsonRendererNodesFactory$renderDocumentNodeGen.executeGeneric(JsonRendererNodesFactory.java:84)
    at org.pkl.core.ast.member.FunctionNode.execute(FunctionNode.java:119)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:718)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:641)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:574)
    at org.graalvm.nativeimage.builder/com.oracle.svm.truffle.api.SubstrateOptimizedCallTarget.invokeCallBoundary(SubstrateOptimizedCallTarget.java:115)
    at com.oracle.svm.svm_enterprise/com.oracle.svm.enterprise.truffle.SubstrateEnterpriseOptimizedCallTarget.a(stripped:284)
    at com.oracle.svm.svm_enterprise/com.oracle.svm.enterprise.truffle.SubstrateEnterpriseOptimizedCallTarget.doInvoke(stripped:250)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:504)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:69)
    at org.pkl.core.ast.expression.member.InvokeMethodVirtualNode.evalCached(InvokeMethodVirtualNode.java:136)
    at org.pkl.core.ast.expression.member.InvokeMethodVirtualNodeGen.executeAndSpecialize(InvokeMethodVirtualNodeGen.java:272)
    at org.pkl.core.ast.expression.member.InvokeMethodVirtualNodeGen.executeGeneric(InvokeMethodVirtualNodeGen.java:193)
    at org.pkl.core.ast.PklRootNode.executeBody(PklRootNode.java:41)
    at org.pkl.core.ast.MemberNode.executeBody(MemberNode.java:71)
    at org.pkl.core.ast.member.TypeCheckedPropertyNode.evalTypedObjectCached(TypeCheckedPropertyNode.java:55)
    at org.pkl.core.ast.member.TypeCheckedPropertyNodeGen.executeAndSpecialize(TypeCheckedPropertyNodeGen.java:135)
    at org.pkl.core.ast.member.TypeCheckedPropertyNodeGen.execute(TypeCheckedPropertyNodeGen.java:100)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:718)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:641)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:574)
    at org.graalvm.nativeimage.builder/com.oracle.svm.truffle.api.SubstrateOptimizedCallTarget.invokeCallBoundary(SubstrateOptimizedCallTarget.java:115)
    at com.oracle.svm.svm_enterprise/com.oracle.svm.enterprise.truffle.SubstrateEnterpriseOptimizedCallTarget.a(stripped:284)
    at com.oracle.svm.svm_enterprise/com.oracle.svm.enterprise.truffle.SubstrateEnterpriseOptimizedCallTarget.doInvoke(stripped:250)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callIndirect(OptimizedCallTarget.java:486)
    at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.call(OptimizedCallTarget.java:467)
    at org.graalvm.truffle/com.oracle.truffle.api.nodes.IndirectCallNode$1.call(IndirectCallNode.java:91)
    at org.pkl.core.runtime.VmUtils.doReadMember(VmUtils.java:297)
    at org.pkl.core.runtime.VmUtils.readMemberOrNull(VmUtils.java:237)
    at org.pkl.core.runtime.VmUtils.readMemberOrNull(VmUtils.java:200)
    at org.pkl.core.runtime.VmUtils.readMember(VmUtils.java:180)
    at org.pkl.core.runtime.VmUtils.readTextProperty(VmUtils.java:170)
    at org.pkl.core.EvaluatorImpl.lambda$evaluateOutputText$3(EvaluatorImpl.java:137)
    at org.pkl.core.EvaluatorImpl.lambda$doEvaluate$13(EvaluatorImpl.java:352)
    at org.pkl.core.EvaluatorImpl.doEvaluate(EvaluatorImpl.java:300)
    at org.pkl.core.EvaluatorImpl.doEvaluate(EvaluatorImpl.java:348)
    at org.pkl.core.EvaluatorImpl.evaluateOutputText(EvaluatorImpl.java:133)
    at org.pkl.core.EvaluatorImpl.evaluateExpressionString(EvaluatorImpl.java:209)
    at org.pkl.cli.CliEvaluator.writeOutput(CliEvaluator.kt:179)
    at org.pkl.cli.CliEvaluator.doRun(CliEvaluator.kt:99)
    at org.pkl.commons.cli.CliCommand.run(CliCommand.kt:45)
    at org.pkl.cli.commands.EvalCommand.run(EvalCommand.kt:86)
    at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:198)
    at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:211)
    at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:18)
    at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:400)
    at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:397)
    at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:415)
    at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:440)
    at org.pkl.cli.Main$main$1.invoke(Main.kt:52)
    at org.pkl.cli.Main$main$1.invoke(Main.kt:40)
    at org.pkl.commons.cli.CliMainKt.cliMain(CliMain.kt:31)
    at org.pkl.cli.Main.main(Main.kt:40

occurs when:

sections = import("@sections/example/section.pkl")

when section.pkl includes:

styling = import*("styles/*.pkl")
bioball commented 8 months ago

@othompson2 curious why you closed this. Did this get fixed somehow?

othompson2 commented 8 months ago

Apologies I should've left a comment. I revisited the issue today after working round it and didn't seem to be able to recreate it. However looking at it now its actually because I've switched the direction of the imports and am using modules throughout, so I am no longer using an inline imports which appears to have resolved the issue.

The following works:

sections = import*("sections/*.pkl")

when the files in that folder have the following:

amends "@sections/example/Example.pkl"

So I do believe its still an issue my bad.