{"record":{"id":"7d257a924fe8376a","repo":"apple/pkl","slug":"cannotanalyzebecausesyntaxerror","errorCode":"cannotAnalyzeBecauseSyntaxError","errorMessage":"cannotAnalyzeBecauseSyntaxError","messagePattern":"cannotAnalyzeBecauseSyntaxError","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/runtime/VmImportAnalyzer.java","lineNumber":90,"sourceCode":"    resolvedImports.put(moduleUri, resolvedModuleKey.getUri());\n    for (var imprt : collectedImports) {\n      if (imports.containsKey(imprt.moduleUri)) {\n        continue;\n      }\n      analyzeSingle(imprt.moduleUri, imprt.resolvedModuleKey, context, imports, resolvedImports);\n    }\n  }\n\n  private static Set<ImportEntry> collectImports(\n      ResolvedModuleKey resolvedModuleKey,\n      ModuleResolver moduleResolver,\n      SecurityManager securityManager) {\n    List<Entry> importsAndReads;\n    var moduleKey = resolvedModuleKey.getOriginal();\n    try {\n      importsAndReads = ImportsAndReadsParser.parse(moduleKey, resolvedModuleKey);\n    } catch (VmException err) {\n      throw new VmExceptionBuilder()\n          .evalError(\"cannotAnalyzeBecauseSyntaxError\", moduleKey.getUri())\n          .wrapping(err)\n          .build();\n    } catch (IOException err) {\n      throw new VmExceptionBuilder().evalError(\"ioErrorLoadingModule\", moduleKey.getUri()).build();\n    }\n    var result = new HashSet<ImportEntry>();\n    for (var entry : importsAndReads) {\n      if (!entry.isModule()) {\n        continue;\n      }\n      try {\n        if (entry.isGlob()) {\n          var theModuleKey =\n              moduleResolver.resolve(moduleKey.resolveUri(IoUtils.toUri(entry.stringValue())));\n          var elements =\n              GlobResolver.resolveGlob(\n                  securityManager,","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/runtime/VmImportAnalyzer.java#L72-L108","documentation":"During import analysis, Pkl parses each imported module to discover its own imports/read() calls. If that parse fails with a VmException (syntax error), the analyzer rethrows cannotAnalyzeBecauseSyntaxError with the module URI, wrapping the original syntax error.","triggerScenarios":"An imported module contains invalid Pkl syntax; ImportsAndReadsParser.parse() raises a VmException during collectImports.","commonSituations":"Typos in a dependency module file; editing a module and introducing a syntax error; a stale cached/dependency module that does not parse.","solutions":["Fix the syntax error in the module named by the URI (the wrapped cause shows the exact location)","If the module is external/dependency, update or pin the correct package version","Re-run evaluation after fixing the file"],"exampleFix":"// before (broken.pkl)\nfoo = = 1\n// after\nfoo = 1","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { analyzeImports(uri) } catch (e) { if (e.code === 'cannotAnalyzeBecauseSyntaxError') { reportSyntaxError(e.cause) } else throw e }","preventionTips":["Lint/format modules with `pkl format` before evaluation","Keep dependency modules at versions known to parse","Run syntax checks in CI"],"tags":["pkl","syntax","import"],"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-14T16:17:12.679Z"}