Skip to content

Commit 20d8187

Browse files
authored
Improve error message for 'package-registry publish' (#6576)
* Improve error message for 'package-registry publish' Motivation: When registry publish fails with client error, the current error message is "Error: failed publishing: invalid registry response status '400', expected '[201, 202]'", which doesn't provide much information on what went wrong. rdar://109410245 Modifications: - Wrap 4xx status response in `RegistryError.clientError` and 5xx in `RegistryError.serverError`. Both errors include response body as details. - Change `package-registry publish` to throw the wrapped `clientError` such that more details (i.e., response body) get displayed. * Don't lose failedPublishing context
1 parent c56e1ee commit 20d8187

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Sources/PackageRegistry/RegistryClient.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,9 +1611,14 @@ public final class RegistryClient: Cancellable {
16111611
return RegistryError.unauthorized
16121612
case 403:
16131613
return RegistryError.forbidden
1614+
case 400...499:
1615+
return RegistryError.clientError(
1616+
code: response.statusCode,
1617+
details: response.body.flatMap { String(data: $0, encoding: .utf8) } ?? ""
1618+
)
16141619
case 501:
16151620
return RegistryError.authenticationMethodNotSupported
1616-
case 500, 502, 503:
1621+
case 500...599:
16171622
return RegistryError.serverError(
16181623
code: response.statusCode,
16191624
details: response.body.flatMap { String(data: $0, encoding: .utf8) } ?? ""
@@ -1673,6 +1678,7 @@ public enum RegistryError: Error, CustomStringConvertible {
16731678
case failedPublishing(Error)
16741679
case missingPublishingLocation
16751680
case serverError(code: Int, details: String)
1681+
case clientError(code: Int, details: String)
16761682
case unauthorized
16771683
case authenticationMethodNotSupported
16781684
case forbidden
@@ -1771,6 +1777,8 @@ public enum RegistryError: Error, CustomStringConvertible {
17711777
return "response missing registry source archive"
17721778
case .serverError(let code, let details):
17731779
return "server error \(code): \(details)"
1780+
case .clientError(let code, let details):
1781+
return "client error \(code): \(details)"
17741782
case .unauthorized:
17751783
return "missing or invalid authentication credentials"
17761784
case .authenticationMethodNotSupported:

Sources/PackageRegistryTool/PackageRegistryTool+Publish.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import Workspace
2222
@_implementationOnly import X509 // FIXME: need this import or else SwiftSigningIdentity initializer fails
2323

2424
import struct TSCBasic.ByteString
25-
import struct TSCBasic.SHA256
2625
import struct TSCBasic.RegEx
26+
import struct TSCBasic.SHA256
2727

2828
import struct TSCUtility.Version
2929

0 commit comments

Comments
 (0)