{"record":{"id":"2d51dc9f7b72560b","repo":"apple/pkl","slug":"failed-to-download-some-packages-failed-to-downlo","errorCode":null,"errorMessage":"Failed to download some packages.\nFailed to download $uri because:\n${error.message}","messagePattern":"Failed to download some packages\\.\nFailed to download \\$uri because:\n(.+?)","errorType":"exception","errorClass":"CliException","httpStatus":null,"severity":"error","filePath":"pkl-cli/src/main/kotlin/org/pkl/cli/CliPackageDownloader.kt","lineNumber":51,"sourceCode":"    }\n    val packageResolver = PackageResolver.getInstance(securityManager, httpClient, moduleCacheDir)\n    val errors = mutableMapOf<PackageUri, Throwable>()\n    for (pkg in packageUris) {\n      try {\n        packageResolver.downloadPackage(pkg, pkg.checksums, noTransitive)\n      } catch (e: Throwable) {\n        errors[pkg] = e\n      }\n    }\n    when (errors.size) {\n      0 -> return\n      1 ->\n        throw CliException(\n          errors.values.single().message\n            ?: (\"An unexpected error occurred: \" + errors.values.single())\n        )\n      else ->\n        throw CliException(\n          buildString {\n            appendLine(\"Failed to download some packages.\")\n            for ((uri, error) in errors) {\n              appendLine()\n              appendLine(\"Failed to download $uri because:\")\n              appendLine(\"${error.message}\")\n            }\n          }\n        )\n    }\n  }\n}\n","sourceCodeStart":33,"sourceCodeEnd":64,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-cli/src/main/kotlin/org/pkl/cli/CliPackageDownloader.kt#L33-L64","documentation":"When two or more packages fail to download, the CLI aggregates all failures into one CliException listing \"Failed to download some packages.\" followed by each URI and its error message. It lets you see every failure in one run instead of fixing them one at a time.","triggerScenarios":"Running `pkl package download pkgA pkgB ...` where two or more package downloads throw (network errors, bad URIs, checksum mismatches, missing versions).","commonSituations":"Batch downloads in CI after a registry outage; migrating packages to a new repository host where several URIs are wrong; air-gapped environments where all remote fetches fail.","solutions":["Read the per-URI causes in the message and fix each (URI, version, checksums, network).","Retry after restoring network/registry access.","Split the batch to isolate a failing package if the aggregate message is unclear.","Use `--no-transitive` if a transitive dependency's resolution is failing."],"exampleFix":"# before\npkl package download package://old.example.com/a@1.0.0 package://old.example.com/b@1.0.0\n# after (URIs migrated to new host)\npkl package download package://example.com/a@1.0.0 package://example.com/b@1.0.0","handlingStrategy":"try-catch","validationCode":"// pre-check each package URI resolves, collecting failures before the batch download\nval failures = uris.groupBy { it.host }.mapValues { (host, us) -> probeAll(us) }.filterValues { it.isNotEmpty() }","typeGuard":null,"tryCatchPattern":"try {\n  pklCli.runPackageDownload(uris)\n} catch (e: CliException) {\n  val failedUris = parseFailedUris(e.message ?: \"\")\n  failedUris.forEach { fixOrSkip(it) }\n}","preventionTips":["Download packages one at a time when first migrating to a new registry.","Monitor registry/network health before large batch downloads.","Keep package URIs centralized so migrations are one-line changes."],"tags":["cli","package-download","network","batch"],"backgroundTag":"http-request-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"}