{"record":{"id":"bc5127c12567248d","repo":"apple/pkl","slug":"packagetestsfailed","errorCode":"packageTestsFailed","errorMessage":"ErrorMessages.create(\"packageTestsFailed\", project.`package`!!.uri())","messagePattern":"ErrorMessages\\.create\\(\"packageTestsFailed\", project\\.`package`!!\\.uri\\(\\)\\)","errorType":"error_code","errorClass":"CliException","httpStatus":null,"severity":"error","filePath":"pkl-cli/src/main/kotlin/org/pkl/cli/CliProjectPackager.kt","lineNumber":53,"sourceCode":"  private val consoleWriter: Writer = System.out.writer(),\n  private val errWriter: Writer = System.err.writer(),\n) : CliProjectCommand(baseOptions, projectDirs) {\n\n  private fun runApiTests(project: Project) {\n    val apiTests = project.`package`!!.apiTests()\n    if (apiTests.isEmpty()) return\n    val normalizeApiTests = apiTests.map { project.projectDir.resolve(it).toUri() }\n    val testRunner =\n      CliTestRunner(\n        cliOptions.copy(sourceModules = normalizeApiTests, projectDir = project.projectDir),\n        testOptions = testOptions,\n        consoleWriter = consoleWriter,\n        errWriter = errWriter,\n      )\n    try {\n      testRunner.run()\n    } catch (e: CliTestException) {\n      throw CliException(ErrorMessages.create(\"packageTestsFailed\", project.`package`!!.uri()))\n    }\n  }\n\n  override fun doRun() {\n    val projects = buildList {\n      for (projectFile in normalizedProjectFiles) {\n        val project = loadProject(projectFile)\n        project.`package`\n          ?: throw CliException(\n            ErrorMessages.create(\"noPackageDefinedByProject\", project.projectFileUri)\n          )\n        runApiTests(project)\n        add(project)\n      }\n    }\n    // Require that all local projects are included\n    projects.forEach { proj ->\n      proj.dependencies.localDependencies().values.forEach { localDep ->","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-cli/src/main/kotlin/org/pkl/cli/CliProjectPackager.kt#L35-L71","documentation":"Thrown by CliProjectPackager.runApiTests when the test run executed as part of `pkl project package` fails with a CliTestException. Packaging a project first runs the project's tests (via the test runner), and if any test fails the packaging is aborted with this error so a broken package is never published. The message is built from the packageTestsFailed ErrorMessages template, parameterized with the package URI.","triggerScenarios":"Running `pkl project package` on a project whose Pkl tests fail; a dependency or API test declared in the project fails during the packaging step.","commonSituations":"Recently edited code broke a test before packaging; a test depends on an external resource (network, file) unavailable in CI; package.json/dependencies changed and tests that verify imports no longer pass.","solutions":["Run `pkl test` on the project separately and fix the failing tests before packaging","Inspect the test output above this error for the actual test failure details","Re-run `pkl project package` after the tests pass"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { packageProject() } catch (CliException e) { if (String e.getMessage() contains \"tests failed\") rerunPklTest(); else throw e; }","preventionTips":["Gate packaging on a passing `pkl test` run in CI","Pin test dependencies so packaging environments are reproducible"],"tags":["cli","pkl","testing","packaging"],"backgroundTag":"package-tests-failed","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"}