{"record":{"id":"196aa86879db8018","repo":"apple/pkl","slug":"vmutils-tovmexception-e-source-repl-text","errorCode":null,"errorMessage":"VmUtils.toVmException(e, source, REPL_TEXT)","messagePattern":"VmUtils\\.toVmException\\(e, source, REPL_TEXT\\)","errorType":"exception","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/runtime/VmUtils.java","lineNumber":977,"sourceCode":"    for (var line = startLine; line <= endLine; line++) {\n      sourceLines.add(section.getSource().getCharacters(line).toString());\n    }\n\n    return new StackFrame(\n        moduleUri,\n        memberName,\n        sourceLines,\n        startLine,\n        section.getStartColumn(),\n        endLine,\n        section.getEndColumn());\n  }\n\n  private static Expr parseExpressionNode(String expression, Source source) {\n    try {\n      return new Parser().parseExpressionInput(expression);\n    } catch (ParserError e) {\n      throw VmUtils.toVmException(e, source, REPL_TEXT);\n    }\n  }\n\n  /**\n   * Create a fake module that declares all the local properties that exist in {@code module}, so\n   * that AstBuilder can correctly resolve variables.\n   *\n   * <p>Additionally, return a {@link org.pkl.parser.syntax.Node} with its span calculated in terms\n   * of this fake module.\n   *\n   * <p>This created module is never executed.\n   */\n  public static Pair<String, org.pkl.parser.syntax.Node> buildSyntheticModuleText(\n      org.pkl.parser.syntax.Node syntaxNode, VmTyped module, String srcText) {\n    if (syntaxNode instanceof ModuleDecl) {\n      return Pair.of(srcText, syntaxNode);\n    }\n    var sb = new StringBuilder();","sourceCodeStart":959,"sourceCodeEnd":995,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/runtime/VmUtils.java#L959-L995","documentation":"In the REPL, expressions typed at the prompt are parsed with Parser.parseExpressionInput; if that fails, the ParserError is converted to a PklException with the REPL pseudo-source and REPL_TEXT as module name. It means the entered text is not a valid standalone Pkl expression.","triggerScenarios":"Typing an incomplete or invalid expression into the Pkl REPL, or programmatic callers of the REPL expression-parsing helper passing malformed input.","commonSituations":"Pasting multi-statement or declaration-only code (e.g. class or module definitions) where only an expression is allowed; unclosed brackets; using syntax valid in modules but not in expression position.","solutions":["Fix the expression so it is a single valid Pkl expression (declarations must be entered differently).","Check for unbalanced parentheses/brackets or trailing tokens.","Wrap declarations: use the REPL's dedicated declaration input mode rather than expression mode.","Test the expression in a scratch .pkl file (`x = <expr>`) to isolate the syntax problem."],"exampleFix":"// before (REPL input)\nfoo = 1 +\n// after\nfoo = 1 + 2","handlingStrategy":"validation","validationCode":"// Sanity-check REPL input before sending\nif (input.trim().isEmpty() || input.contains(\"\\n\\n\")) { /* prompt user to simplify */ }","typeGuard":null,"tryCatchPattern":"try {\n  repl.evaluate(input);\n} catch (PklException e) {\n  System.err.println(\"Invalid expression: \" + e.getMessage());\n}","preventionTips":["Enter only single expressions at the REPL expression prompt; use declaration mode for classes/properties.","Balance brackets before submitting input.","Test complex expressions in a scratch .pkl file first."],"tags":["pkl","repl","parser","syntax-error"],"backgroundTag":"json-parse-error","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"}