{"record":{"id":"b4dff969f5930bce","repo":"apple/pkl","slug":"failed-to-parse-transitive-imports-from-outputfi","errorCode":null,"errorMessage":"Failed to parse transitive imports from ${outputFile}","messagePattern":"Failed to parse transitive imports from (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pkl-gradle/src/main/java/org/pkl/gradle/utils/PluginUtils.java","lineNumber":164,"sourceCode":"   * assumes JSON format and should only be called for those tasks.\n   *\n   * @param outputFile the output file produced by the analyze imports task\n   * @return the list of file-based transitive import paths\n   */\n  public static List<File> parseTransitiveFiles(RegularFile outputFile) {\n    if (!outputFile.getAsFile().exists()) {\n      return Collections.emptyList();\n    }\n    try {\n      var contents = Files.readString(outputFile.getAsFile().toPath());\n      var importGraph = ImportGraph.parseFromJson(contents);\n      var imports = importGraph.resolvedImports().values();\n      return imports.stream()\n          .filter(it -> it.getScheme().equalsIgnoreCase(\"file\"))\n          .map(File::new)\n          .toList();\n    } catch (Exception e) {\n      throw new RuntimeException(\n          \"Failed to parse transitive imports from \" + outputFile.getAsFile(), e);\n    }\n  }\n\n  /**\n   * Equivalent to {@code provider.map(it -> f.apply(it)).getOrNull()}.\n   *\n   * <p>This function is necessary because in some cases doing {@code\n   * someProvider.map(...).getOrNull()} may trigger validation errors inside Gradle, when {@code\n   * someProvider} is derived from a property.\n   */\n  public static <T, U> @Nullable U mapAndGetOrNull(Provider<T> provider, Function<T, U> f) {\n    @Nullable T value = provider.getOrNull();\n    return value == null ? null : f.apply(value);\n  }\n\n  public static TestReporter toTestReporter(Provider<String> input) {\n    var inputStr = input.getOrNull();","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-gradle/src/main/java/org/pkl/gradle/utils/PluginUtils.java#L146-L182","documentation":"parseTransitiveFiles runs the Pkl analyzer/import graph over a dependency output file to discover transitive imports. If any exception occurs while parsing the import graph or processing its resolved imports (filtering file-scheme URIs into Files), it is rethrown as this RuntimeException naming the output file.","triggerScenarios":"Calling a task that resolves transitive imports (e.g. PklDependencyTask) when the dependency output file is missing, corrupt, or produced by an incompatible Pkl version, or when the import graph computation throws internally.","commonSituations":"Stale or partially written dependency cache after an interrupted build, Pkl version upgrades changing the output file format, deleted project source files listed in the import graph, or configuration errors inside imported modules.","solutions":["Clean and regenerate the output file (gradle clean or delete the Pkl dependency cache) and rerun the task","Verify all transitively imported Pkl modules exist and evaluate without errors (run pkl eval manually)","Check Pkl plugin and CLI version compatibility after upgrades","Inspect the cause (wrapped exception) to identify the underlying parse/IO failure"],"exampleFix":"// before\n// stale cached output reused\n// after\n./gradlew clean pklProject --rerun-tasks","handlingStrategy":"try-catch","validationCode":"// before running transitive import resolution:\nif (!outputFile.getAsFile().exists()) throw new GradleException(\"Dependency output missing: \" + outputFile.getAsFile() + \"; run the generating task first\");","typeGuard":null,"tryCatchPattern":"try {\n  files = PluginUtils.parseTransitiveFiles(provider, fn);\n} catch (RuntimeException e) {\n  logger.warn(\"Transitive import parse failed: {}\", e.getMessage());\n  files = List.of(); // or fail fast depending on build strictness\n}","preventionTips":["Run `gradle clean`/delete Pkl caches after plugin or Pkl version upgrades","Keep the Pkl CLI/plugin versions aligned","Ensure all imported modules exist and evaluate before dependency resolution","Treat the wrapped cause as the real failure and fix it, not just the wrapper"],"tags":["gradle","import-graph","parse-error","build"],"backgroundTag":"file-read-failed","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"}