{"record":{"id":"da492c0704b9a3c0","repo":"apple/pkl","slug":"cannot-generate-junit-report-for-moduleuri-a-rep","errorCode":null,"errorMessage":"Cannot generate JUnit report for $moduleUri.\nA report with the same name was already generated.\n\nTo fix, provide a different name for this module by adding a module header.","messagePattern":"Cannot generate JUnit report for \\$moduleUri\\.\nA report with the same name was already generated\\.\n\nTo fix, provide a different name for this module by adding a module header\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pkl-cli/src/main/kotlin/org/pkl/cli/CliTestRunner.kt","lineNumber":98,"sourceCode":"        try {\n          val results = evaluator.evaluateTest(uri(moduleUri), testOptions.overwrite)\n          allTestResults.add(results)\n          if (!failed) {\n            failed = results.failed()\n            isExampleWrittenFailure = results.isExampleWrittenFailure.and(isExampleWrittenFailure)\n          }\n          val tmpWriter = StringWriter()\n          reporter.report(results, tmpWriter)\n          val report = tmpWriter.toString()\n          consoleWriter.write(report)\n          if (report.isNotEmpty() && sources.size > 1 && idx != sources.size - 1) {\n            consoleWriter.append('\\n')\n          }\n          consoleWriter.flush()\n          if (junitDir != null) {\n            val moduleName = \"${results.moduleName}.xml\"\n            if (moduleName in moduleNames) {\n              throw RuntimeException(\n                \"\"\"\n                  Cannot generate JUnit report for $moduleUri.\n                  A report with the same name was already generated.\n                  \n                  To fix, provide a different name for this module by adding a module header.\n                \"\"\"\n                  .trimIndent()\n              )\n            }\n            moduleNames += moduleName\n\n            if (!testOptions.junitAggregateReports) {\n              JUnitReporter().reportToPath(results, junitDir.resolve(moduleName))\n            }\n          }\n        } catch (ex: Exception) {\n          errWriter.appendLine(\"Error evaluating module ${moduleUri.path}:\")\n          errWriter.write(ex.message ?: \"\")","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-cli/src/main/kotlin/org/pkl/cli/CliTestRunner.kt#L80-L116","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","solutions":["Add a unique module header to one of the colliding modules, e.g. `module my.project.tests.otherTest`.","Rename one of the conflicting test files so derived module names differ.","Check the listed modules for duplicates (same file passed twice) and remove the duplicate."],"exampleFix":"// before: tests/a/test.pkl and tests/b/test.pkl, both unnamed -> both map to test.xml\n// after: tests/b/test.pkl\nmodule my.pkg.bTest\n\n...","handlingStrategy":"validation","validationCode":"// pre-check module name uniqueness when using --junit-dir\nval names = testModules.map { it.moduleName }\nrequire(names.size == names.toSet().size) { \"duplicate module names would collide in JUnit reports\" }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give every test module a unique `module` header when generating JUnit reports.","Avoid naming multiple test files identically in different directories.","Sanity-check the module list for accidental duplicates before running with --junit-dir."],"tags":["junit-report","name-collision","testing","cli"],"backgroundTag":"file-already-exists","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"}