{"record":{"id":"2abfa5ed239a659f","repo":"apple/pkl","slug":"cannotinstallpackagewithnocache","errorCode":"cannotInstallPackageWithNoCache","errorMessage":"ErrorMessages.create(\"cannotInstallPackageWithNoCache\")","messagePattern":"ErrorMessages\\.create\\(\"cannotInstallPackageWithNoCache\"\\)","errorType":"error_code","errorClass":"PklException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/project/ProjectPackager.java","lineNumber":132,"sourceCode":"      SecurityManager securityManager,\n      HttpClient httpClient,\n      boolean skipPublishCheck,\n      boolean install,\n      @Nullable Path cacheDir,\n      Writer outputWriter) {\n    this.projects = projects;\n    this.workingDir = workingDir;\n    this.outputPathPattern = outputPathPattern;\n    this.stackFrameTransformer = stackFrameTransformer;\n    this.color = color;\n    this.securityManager = securityManager;\n    // intentionally use InMemoryPackageResolver\n    this.packageResolver = PackageResolver.getInstance(securityManager, httpClient, null);\n    this.skipPublishCheck = skipPublishCheck;\n    this.outputWriter = outputWriter;\n    if (install) {\n      if (cacheDir == null) {\n        throw new PklException(ErrorMessages.create(\"cannotInstallPackageWithNoCache\"));\n      }\n      packageWriteResolver = PackageResolver.getInstance(securityManager, httpClient, cacheDir);\n    } else {\n      packageWriteResolver = null;\n    }\n  }\n\n  private void writeLine(String line) throws IOException {\n    outputWriter.write(line);\n    outputWriter.write(IoUtils.getLineSeparator());\n  }\n\n  public void createPackages() throws IOException {\n    for (var project : projects) {\n      var packageResult = doPackage(project);\n      writeLine(IoUtils.relativize(packageResult.metadataFile(), workingDir).toString());\n      writeLine(IoUtils.relativize(packageResult.metadataChecksumFile(), workingDir).toString());\n      writeLine(IoUtils.relativize(packageResult.zipFile(), workingDir).toString());","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/project/ProjectPackager.java#L114-L150","documentation":"ProjectPackager was constructed with install=true (packages should be installed into the local cache), but no cacheDir was provided. Since installation requires a writable cache directory, construction fails immediately with PklException('cannotInstallPackageWithNoCache').","triggerScenarios":"new ProjectPackager(securityManager, httpClient, null /* cacheDir */, install=true, skipPublishCheck, outputWriter).","commonSituations":"Embedding Pkl with install enabled but cache dir unset (null); CLI flag combinations where --install is used without a cache location configured.","solutions":["Pass a valid cache directory path when constructing ProjectPackager with install=true","Set install=false if package installation is not needed","Configure the environment so a default cache directory (e.g. ~/.pkl/cache) is available"],"exampleFix":"// before\nnew ProjectPackager(security, httpClient, null, true, false, writer);\n// after\nnew ProjectPackager(security, httpClient, Path.of(\"~/.pkl/cache\"), true, false, writer);","handlingStrategy":"validation","validationCode":"if (install && cacheDir == null) throw new IllegalArgumentException(\"cacheDir is required when install=true\");","typeGuard":"boolean canInstall(Path cacheDir) { return cacheDir != null; }","tryCatchPattern":"try { new ProjectPackager(sec, http, cacheDir, install, skip, out); } catch (PklException e) { /* supply cacheDir or set install=false */ }","preventionTips":["Always configure a cache directory when enabling installation","Default cacheDir to ~/.pkl/cache in embedded setups","Validate flag combinations (install vs cacheDir) at startup"],"tags":["configuration","packaging","cache"],"backgroundTag":"missing-required-config","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}