apple/pkl · error · RuntimeException

Cannot generate JUnit report for $moduleUri. A report with t

Error message

Cannot generate JUnit report for $moduleUri.
A report with the same name was already generated.

To fix, provide a different name for this module by adding a module header.

What it means

When JUnit report generation is enabled (--junit-dir), the runner writes one XML file per test module named after the module's name (moduleName + ".xml"). If two modules resolve to the same report filename, the second write would silently overwrite the first, so evalTest throws a RuntimeException instead. The fix is to give one of the modules a distinct module name via a module header.

Source

Thrown at pkl-cli/src/main/kotlin/org/pkl/cli/CliTestRunner.kt:98

        try {
          val results = evaluator.evaluateTest(uri(moduleUri), testOptions.overwrite)
          allTestResults.add(results)
          if (!failed) {
            failed = results.failed()
            isExampleWrittenFailure = results.isExampleWrittenFailure.and(isExampleWrittenFailure)
          }
          val tmpWriter = StringWriter()
          reporter.report(results, tmpWriter)
          val report = tmpWriter.toString()
          consoleWriter.write(report)
          if (report.isNotEmpty() && sources.size > 1 && idx != sources.size - 1) {
            consoleWriter.append('\n')
          }
          consoleWriter.flush()
          if (junitDir != null) {
            val moduleName = "${results.moduleName}.xml"
            if (moduleName in moduleNames) {
              throw RuntimeException(
                """
                  Cannot generate JUnit report for $moduleUri.
                  A report with the same name was already generated.
                  
                  To fix, provide a different name for this module by adding a module header.
                """
                  .trimIndent()
              )
            }
            moduleNames += moduleName

            if (!testOptions.junitAggregateReports) {
              JUnitReporter().reportToPath(results, junitDir.resolve(moduleName))
            }
          }
        } catch (ex: Exception) {
          errWriter.appendLine("Error evaluating module ${moduleUri.path}:")
          errWriter.write(ex.message ?: "")

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Add a unique module header to one of the colliding modules, e.g. `module my.project.tests.otherTest`.
  2. Rename one of the conflicting test files so derived module names differ.
  3. Check the listed modules for duplicates (same file passed twice) and remove the duplicate.

Example fix

// before: tests/a/test.pkl and tests/b/test.pkl, both unnamed -> both map to test.xml
// after: tests/b/test.pkl
module my.pkg.bTest

...
Defensive patterns

Strategy: validation

Validate before calling

// pre-check module name uniqueness when using --junit-dir
val names = testModules.map { it.moduleName }
require(names.size == names.toSet().size) { "duplicate module names would collide in JUnit reports" }

Prevention

When it happens

Trigger: Running `pkl test --junit-dir <dir> <modules>` where two listed test modules have identical module names (no unique `module` header), so both map to `<moduleName>.xml`.

Common situations: Two test files in different directories both lack a module header and default to the same derived name (e.g. both `test.pkl`); test suites copied from another project keep duplicate module names; merging test directories introduces collisions.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/da492c0704b9a3c0. Report an issue: GitHub.