apple/pkl · error · CliException

packageTestsFailed

packageTestsFailed

Error message

ErrorMessages.create("packageTestsFailed", project.`package`!!.uri())

What it means

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.

Source

Thrown at pkl-cli/src/main/kotlin/org/pkl/cli/CliProjectPackager.kt:53

  private val consoleWriter: Writer = System.out.writer(),
  private val errWriter: Writer = System.err.writer(),
) : CliProjectCommand(baseOptions, projectDirs) {

  private fun runApiTests(project: Project) {
    val apiTests = project.`package`!!.apiTests()
    if (apiTests.isEmpty()) return
    val normalizeApiTests = apiTests.map { project.projectDir.resolve(it).toUri() }
    val testRunner =
      CliTestRunner(
        cliOptions.copy(sourceModules = normalizeApiTests, projectDir = project.projectDir),
        testOptions = testOptions,
        consoleWriter = consoleWriter,
        errWriter = errWriter,
      )
    try {
      testRunner.run()
    } catch (e: CliTestException) {
      throw CliException(ErrorMessages.create("packageTestsFailed", project.`package`!!.uri()))
    }
  }

  override fun doRun() {
    val projects = buildList {
      for (projectFile in normalizedProjectFiles) {
        val project = loadProject(projectFile)
        project.`package`
          ?: throw CliException(
            ErrorMessages.create("noPackageDefinedByProject", project.projectFileUri)
          )
        runApiTests(project)
        add(project)
      }
    }
    // Require that all local projects are included
    projects.forEach { proj ->
      proj.dependencies.localDependencies().values.forEach { localDep ->

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Run `pkl test` on the project separately and fix the failing tests before packaging
  2. Inspect the test output above this error for the actual test failure details
  3. Re-run `pkl project package` after the tests pass
Defensive patterns

Strategy: try-catch

Try / catch

try { packageProject() } catch (CliException e) { if (String e.getMessage() contains "tests failed") rerunPklTest(); else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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