apple/pkl · error · PklException

cannotInstallPackageWithNoCache

cannotInstallPackageWithNoCache

Error message

ErrorMessages.create("cannotInstallPackageWithNoCache")

What it means

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').

Solutions

  1. Pass a valid cache directory path when constructing ProjectPackager with install=true
  2. Set install=false if package installation is not needed
  3. Configure the environment so a default cache directory (e.g. ~/.pkl/cache) is available

Example fix

// before
new ProjectPackager(security, httpClient, null, true, false, writer);
// after
new ProjectPackager(security, httpClient, Path.of("~/.pkl/cache"), true, false, writer);
Defensive patterns

Strategy: validation

Validate before calling

if (install && cacheDir == null) throw new IllegalArgumentException("cacheDir is required when install=true");

Type guard

boolean canInstall(Path cacheDir) { return cacheDir != null; }

Try / catch

try { new ProjectPackager(sec, http, cacheDir, install, skip, out); } catch (PklException e) { /* supply cacheDir or set install=false */ }

Prevention

When it happens

Trigger: new ProjectPackager(securityManager, httpClient, null /* cacheDir */, install=true, skipPublishCheck, outputWriter).

Common situations: Embedding Pkl with install enabled but cache dir unset (null); CLI flag combinations where --install is used without a cache location configured.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/2abfa5ed239a659f. Report an issue: GitHub.

Appendix: source

Thrown at pkl-core/src/main/java/org/pkl/core/project/ProjectPackager.java:132

      SecurityManager securityManager,
      HttpClient httpClient,
      boolean skipPublishCheck,
      boolean install,
      @Nullable Path cacheDir,
      Writer outputWriter) {
    this.projects = projects;
    this.workingDir = workingDir;
    this.outputPathPattern = outputPathPattern;
    this.stackFrameTransformer = stackFrameTransformer;
    this.color = color;
    this.securityManager = securityManager;
    // intentionally use InMemoryPackageResolver
    this.packageResolver = PackageResolver.getInstance(securityManager, httpClient, null);
    this.skipPublishCheck = skipPublishCheck;
    this.outputWriter = outputWriter;
    if (install) {
      if (cacheDir == null) {
        throw new PklException(ErrorMessages.create("cannotInstallPackageWithNoCache"));
      }
      packageWriteResolver = PackageResolver.getInstance(securityManager, httpClient, cacheDir);
    } else {
      packageWriteResolver = null;
    }
  }

  private void writeLine(String line) throws IOException {
    outputWriter.write(line);
    outputWriter.write(IoUtils.getLineSeparator());
  }

  public void createPackages() throws IOException {
    for (var project : projects) {
      var packageResult = doPackage(project);
      writeLine(IoUtils.relativize(packageResult.metadataFile(), workingDir).toString());
      writeLine(IoUtils.relativize(packageResult.metadataChecksumFile(), workingDir).toString());
      writeLine(IoUtils.relativize(packageResult.zipFile(), workingDir).toString());

View on GitHub (pinned to f3efcbfc9b)