{"record":{"id":"51acbd24be170f8a","repo":"apple/pkl","slug":"yamlparseerror","errorCode":"yamlParseError","errorMessage":"yamlParseError","messagePattern":"yamlParseError","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/stdlib/yaml/ParserNodes.java","lineNumber":81,"sourceCode":"      var uri = (String) VmUtils.readMember(resource, Identifier.URI, callNode);\n      return doParse(self, text, uri);\n    }\n\n    private Object doParse(VmTyped self, String text, String uri) {\n      var converter = PklConverter.fromParser(self);\n      var load = createLoad(self, text, uri, converter);\n\n      try {\n        var document = load.loadFromString(text);\n        return converter.convert(document, List.of());\n      } catch (YamlEngineException e) {\n        if (e.getMessage()\n            .startsWith(\"Number of aliases for non-scalar nodes exceeds the specified\")) {\n          throw exceptionBuilder()\n              .evalError(\"yamlParseErrorTooManyAliases\", getMaxCollectionAliases(self))\n              .build();\n        }\n        throw exceptionBuilder().evalError(\"yamlParseError\").withHint(e.getMessage()).build();\n      }\n    }\n  }\n\n  public abstract static class parseAll extends ExternalMethod1Node {\n    @Specialization\n    @TruffleBoundary\n    protected VmList eval(VmTyped self, String text) {\n      var uri = \"input_string\";\n      return doParseAll(self, text, uri);\n    }\n\n    @Specialization\n    @TruffleBoundary\n    protected Object eval(\n        VmTyped self, VmTyped resource, @Cached(\"create()\") IndirectCallNode callNode) {\n      var text = (String) VmUtils.readMember(resource, Identifier.TEXT, callNode);\n      var uri = (String) VmUtils.readMember(resource, Identifier.URI, callNode);","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/stdlib/yaml/ParserNodes.java#L63-L99","documentation":"`yaml.parse` throws `yamlParseError` when the YAML engine (snakeyaml-engine) fails to parse the input text for any reason other than the alias-limit. The engine exception message is attached as a hint, e.g. syntax errors, bad indentation, invalid characters, duplicate keys, or disallowed tags.","triggerScenarios":"Calling `yaml.parse(text)` where `text` is not valid YAML: wrong indentation, tabs for indentation, unbalanced flow collections, invalid mapping structure, bad escape sequences, or content that is JSON/CSV/XML by mistake. Raised in ParserNodes.doParse.","commonSituations":"Hand-edited YAML config with inconsistent indentation; copying YAML from docs that lost whitespace; parsing JSON-lookalike content with unsupported syntax; files saved with BOM or control characters.","solutions":["Read the hint message to find the line/column of the first syntax error and fix it","Run the text through a YAML linter (yamllint) or an online YAML validator to locate issues","Replace tab characters with spaces — YAML forbids tabs for indentation","Confirm the file is actually YAML and completely downloaded/uncorrupted"],"exampleFix":"// before\nkey:\n\tsubkey: 1\n// after\nkey:\n  subkey: 1","handlingStrategy":"try-catch","validationCode":"// avoid tabs & non-space indentation before parsing\nif (text.contains(\"\\t\")) text = text.replaceAll(\"\\t\", \"  \")","typeGuard":null,"tryCatchPattern":"try {\n  doc = yaml.parse(text)\n} catch (e: PklException) {\n  trace(\"YAML error: ${e.message}\")  // hint has line/column\n  throw e\n}","preventionTips":["Run yamllint in CI on YAML inputs","Use spaces, never tabs, for YAML indentation","Render templates fully before parsing; check for leftover placeholders"],"tags":["yaml","pkl","stdlib","parsing"],"backgroundTag":"yaml-parse-error","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}