{"record":{"id":"0b8fb4e992b15e84","repo":"apple/pkl","slug":"expectedmoduleasargument","errorCode":"expectedModuleAsArgument","errorMessage":"expectedModuleAsArgument","messagePattern":"expectedModuleAsArgument","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/stdlib/base/ModuleClassNodes.java","lineNumber":40,"sourceCode":"import org.pkl.core.runtime.*;\nimport org.pkl.core.stdlib.ExternalMethod1Node;\nimport org.pkl.core.stdlib.PklName;\n\n@PklName(\"Module\")\npublic final class ModuleClassNodes {\n  private ModuleClassNodes() {}\n\n  public abstract static class relativePathTo extends ExternalMethod1Node {\n    @Specialization\n    @TruffleBoundary\n    protected VmList eval(VmObjectLike self, VmObjectLike other) {\n      if (!self.isModuleObject()) {\n        CompilerDirectives.transferToInterpreter();\n        throw exceptionBuilder().evalError(\"expectedModuleAsReceiver\").build();\n      }\n      if (!other.isModuleObject()) {\n        CompilerDirectives.transferToInterpreter();\n        throw exceptionBuilder().evalError(\"expectedModuleAsArgument\").build();\n      }\n      var selfKey = VmUtils.getModuleInfo(self).getModuleKey();\n      var selfUri = selfKey.getUri();\n      var otherKey = VmUtils.getModuleInfo(other).getModuleKey();\n      var otherUri = otherKey.getUri();\n\n      var index = selfUri.toString().lastIndexOf('/');\n      if (index != -1) {\n        var baseUri = URI.create(selfUri.toString().substring(0, index + 1));\n        var relativizedUri = baseUri.relativize(otherUri);\n        if (!relativizedUri.isAbsolute()) {\n          var pathElements = relativizedUri.getPath().split(\"/\");\n          return VmList.create(pathElements, pathElements.length - 1);\n        }\n      }\n\n      throw exceptionBuilder()\n          .evalError(\"noDescendentPathBetweenModules\", selfUri, otherUri)","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/stdlib/base/ModuleClassNodes.java#L22-L58","documentation":"Thrown by Module.relativePathTo when the argument (the other object) is not a module object. The receiver was already verified to be a module, but relativizing a path requires both sides to have module keys/URIs, so a non-module argument is rejected with this error.","triggerScenarios":"Calling module.relativePathTo(x) where x is a plain object, Dynamic, class, or collection rather than an imported module object.","commonSituations":"Passing a nested object or property value instead of the module import, passing a file path string instead of the module, or mixing up argument order with another API that takes paths.","solutions":["Pass an imported module object: `module.relativePathTo(import(\"other.pkl\"))`","Import the target file first and pass the module binding, not a string path","Verify the argument is produced by an import statement, not a property lookup","If you only have a path, import it dynamically or compute the relative path with string/URI utilities instead"],"exampleFix":"// before\nmodule.relativePathTo(\"../lib/other.pkl\") // string, not a module\n// after\nimport \"../lib/other.pkl\"\nmodule.relativePathTo(other)","handlingStrategy":"validation","validationCode":"function isModuleArg(obj: Any): Boolean = obj is Module","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Import the target module and pass the module binding, never a path string","Never pass Dynamic/plain objects to module-to-module APIs","Check the argument is the result of `import \"...\"`"],"tags":["pkl","module","argument","stdlib"],"backgroundTag":"invalid-argument-value","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}