{"record":{"id":"e1766be175bcb4ac","repo":"apple/pkl","slug":"the-evaluator-is-no-longer-available","errorCode":null,"errorMessage":"The evaluator is no longer available","messagePattern":"The evaluator is no longer available","errorType":"exception","errorClass":"PklException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/FileOutputImpl.java","lineNumber":42,"sourceCode":"\n  FileOutputImpl(EvaluatorImpl evaluator, VmTyped fileOutput) {\n    this.evaluator = evaluator;\n    this.fileOutput = fileOutput;\n  }\n\n  /**\n   * Evaluates the text output of this file.\n   *\n   * <p>Will throw {@link PklException} if a normal evaluator error occurs.\n   *\n   * <p>If the evaluator that produced this {@link FileOutput} is closed, an error will be thrown.\n   */\n  public String getText() {\n    try {\n      return evaluator.evaluateOutputText(fileOutput);\n    } catch (PolyglotException e) {\n      if (e.isCancelled()) {\n        throw new PklException(\"The evaluator is no longer available\", e);\n      }\n      throw new PklBugException(e);\n    }\n  }\n\n  @Override\n  public byte[] getBytes() {\n    try {\n      return evaluator.evaluateOutputBytes(fileOutput);\n    } catch (PolyglotException e) {\n      if (e.isCancelled()) {\n        throw new PklException(\"The evaluator is no longer available\", e);\n      }\n      throw new PklBugException(e);\n    }\n  }\n}\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/FileOutputImpl.java#L24-L60","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Read all FileOutput contents (getText/getBytes) inside the evaluator's open scope, before close().","Don't close the evaluator until all outputs are consumed; restructure to consume outputs synchronously in the result handler.","If timeouts cause cancellation, raise the timeout or disable it.","Catch PklException and check the message/cause PolyglotException.isCancelled() to distinguish from real evaluation errors."],"exampleFix":"// before\ntry (Evaluator e = Evaluator.builder(src).build()) {\n  result = e.evaluateOutputFiles(src);\n}\nString text = result.get(\"out\").getText(); // evaluator closed -> cancelled\n// after\ntry (Evaluator e = Evaluator.builder(src).build()) {\n  result = e.evaluateOutputFiles(src);\n  String text = result.get(\"out\").getText(); // consume while open\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  String text = fileOutput.getText();\n} catch (PklException e) {\n  if (e.getCause() instanceof PolyglotException pe && pe.isCancelled()) {\n    throw new IllegalStateException(\"Evaluator closed before output was read\", e);\n  }\n  throw e;\n}","preventionTips":["Consume all FileOutput values inside the try-with-resources evaluator block","Never cache FileOutput objects for later reads after close()","Copy text/bytes eagerly if you need them beyond the evaluator's lifetime","Avoid closing/cancelling the evaluator while output reads are pending"],"tags":["lifecycle","evaluator-closed","cancelled"],"backgroundTag":"invalid-state-transition","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"}