apple/pkl · error · PklException

The evaluator is no longer available

Error message

The evaluator is no longer available

What it means

FileOutputImpl.getText() throws PklException("The evaluator is no longer available") when the underlying evaluateOutputText call throws a PolyglotException with isCancelled()==true, i.e. the evaluator (or its GraalVM context) was closed or the evaluation was cancelled before/during producing the output text. FileOutput results must be consumed while the evaluator is still open.

Solutions

  1. Read all FileOutput contents (getText/getBytes) inside the evaluator's open scope, before close().
  2. Don't close the evaluator until all outputs are consumed; restructure to consume outputs synchronously in the result handler.
  3. If timeouts cause cancellation, raise the timeout or disable it.
  4. Catch PklException and check the message/cause PolyglotException.isCancelled() to distinguish from real evaluation errors.

Example fix

// before
try (Evaluator e = Evaluator.builder(src).build()) {
  result = e.evaluateOutputFiles(src);
}
String text = result.get("out").getText(); // evaluator closed -> cancelled
// after
try (Evaluator e = Evaluator.builder(src).build()) {
  result = e.evaluateOutputFiles(src);
  String text = result.get("out").getText(); // consume while open
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  String text = fileOutput.getText();
} catch (PklException e) {
  if (e.getCause() instanceof PolyglotException pe && pe.isCancelled()) {
    throw new IllegalStateException("Evaluator closed before output was read", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling getText() on a FileOutput after the Evaluator was closed (try-with-resources exit, manual close(), shutdown) or after the evaluation was cancelled (e.g. by a timeout task cancelling the evaluation).

Common situations: Collecting FileOutput objects in a listener and reading them after the try-with-resources evaluator block ends; evaluator closed early due to timeout or cancellation; reading outputs lazily on another thread after close.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at pkl-core/src/main/java/org/pkl/core/FileOutputImpl.java:42

  FileOutputImpl(EvaluatorImpl evaluator, VmTyped fileOutput) {
    this.evaluator = evaluator;
    this.fileOutput = fileOutput;
  }

  /**
   * Evaluates the text output of this file.
   *
   * <p>Will throw {@link PklException} if a normal evaluator error occurs.
   *
   * <p>If the evaluator that produced this {@link FileOutput} is closed, an error will be thrown.
   */
  public String getText() {
    try {
      return evaluator.evaluateOutputText(fileOutput);
    } catch (PolyglotException e) {
      if (e.isCancelled()) {
        throw new PklException("The evaluator is no longer available", e);
      }
      throw new PklBugException(e);
    }
  }

  @Override
  public byte[] getBytes() {
    try {
      return evaluator.evaluateOutputBytes(fileOutput);
    } catch (PolyglotException e) {
      if (e.isCancelled()) {
        throw new PklException("The evaluator is no longer available", e);
      }
      throw new PklBugException(e);
    }
  }
}

View on GitHub (pinned to f3efcbfc9b)