@@ -75,7 +75,7 @@ public struct RPCError: @unchecked Sendable, Hashable, Error {
7575 ///
7676 /// - Parameter status: The status to convert.
7777 public init ? ( status: Status ) {
78- guard let code = Code ( statusCode : status. code) else { return nil }
78+ guard let code = Code ( status. code) else { return nil }
7979 self . init ( code: code, message: status. message, metadata: [ : ] )
8080 }
8181}
@@ -119,16 +119,20 @@ extension RPCError {
119119 /// The numeric value of the error code.
120120 public var rawValue : Int { Int ( self . wrapped. rawValue) }
121121
122- private var wrapped : Status . Code . Wrapped
123- private init ( _ wrapped : Status . Code . Wrapped ) {
124- self . wrapped = wrapped
122+ internal var wrapped : Status . Code . Wrapped
123+ private init ( code : Status . Code . Wrapped ) {
124+ self . wrapped = code
125125 }
126126
127- internal init ? ( statusCode: Status . Code ) {
128- if statusCode == . ok {
127+ /// Creates an error code from the given ``Status/Code-swift.struct``; returns `nil` if the
128+ /// code is ``Status/Code-swift.struct/ok``.
129+ ///
130+ /// - Parameter code: The status code to create this ``RPCError/Code-swift.struct`` from.
131+ public init ? ( _ code: Status . Code ) {
132+ if code == . ok {
129133 return nil
130134 } else {
131- self . wrapped = statusCode . wrapped
135+ self . wrapped = code . wrapped
132136 }
133137 }
134138
@@ -140,44 +144,44 @@ extension RPCError {
140144
141145extension RPCError . Code {
142146 /// The operation was cancelled (typically by the caller).
143- public static let cancelled = Self ( . cancelled)
147+ public static let cancelled = Self ( code : . cancelled)
144148
145149 /// Unknown error. An example of where this error may be returned is if a
146150 /// Status value received from another address space belongs to an error-space
147151 /// that is not known in this address space. Also errors raised by APIs that
148152 /// do not return enough error information may be converted to this error.
149- public static let unknown = Self ( . unknown)
153+ public static let unknown = Self ( code : . unknown)
150154
151155 /// Client specified an invalid argument. Note that this differs from
152156 /// ``failedPrecondition``. ``invalidArgument`` indicates arguments that are
153157 /// problematic regardless of the state of the system (e.g., a malformed file
154158 /// name).
155- public static let invalidArgument = Self ( . invalidArgument)
159+ public static let invalidArgument = Self ( code : . invalidArgument)
156160
157161 /// Deadline expired before operation could complete. For operations that
158162 /// change the state of the system, this error may be returned even if the
159163 /// operation has completed successfully. For example, a successful response
160164 /// from a server could have been delayed long enough for the deadline to
161165 /// expire.
162- public static let deadlineExceeded = Self ( . deadlineExceeded)
166+ public static let deadlineExceeded = Self ( code : . deadlineExceeded)
163167
164168 /// Some requested entity (e.g., file or directory) was not found.
165- public static let notFound = Self ( . notFound)
169+ public static let notFound = Self ( code : . notFound)
166170
167171 /// Some entity that we attempted to create (e.g., file or directory) already
168172 /// exists.
169- public static let alreadyExists = Self ( . alreadyExists)
173+ public static let alreadyExists = Self ( code : . alreadyExists)
170174
171175 /// The caller does not have permission to execute the specified operation.
172176 /// ``permissionDenied`` must not be used for rejections caused by exhausting
173177 /// some resource (use ``resourceExhausted`` instead for those errors).
174178 /// ``permissionDenied`` must not be used if the caller can not be identified
175179 /// (use ``unauthenticated`` instead for those errors).
176- public static let permissionDenied = Self ( . permissionDenied)
180+ public static let permissionDenied = Self ( code : . permissionDenied)
177181
178182 /// Some resource has been exhausted, perhaps a per-user quota, or perhaps the
179183 /// entire file system is out of space.
180- public static let resourceExhausted = Self ( . resourceExhausted)
184+ public static let resourceExhausted = Self ( code : . resourceExhausted)
181185
182186 /// Operation was rejected because the system is not in a state required for
183187 /// the operation's execution. For example, directory to be deleted may be
@@ -197,14 +201,14 @@ extension RPCError.Code {
197201 /// REST Get/Update/Delete on a resource and the resource on the
198202 /// server does not match the condition. E.g., conflicting
199203 /// read-modify-write on the same resource.
200- public static let failedPrecondition = Self ( . failedPrecondition)
204+ public static let failedPrecondition = Self ( code : . failedPrecondition)
201205
202206 /// The operation was aborted, typically due to a concurrency issue like
203207 /// sequencer check failures, transaction aborts, etc.
204208 ///
205209 /// See litmus test above for deciding between ``failedPrecondition``, ``aborted``,
206210 /// and ``unavailable``.
207- public static let aborted = Self ( . aborted)
211+ public static let aborted = Self ( code : . aborted)
208212
209213 /// Operation was attempted past the valid range. E.g., seeking or reading
210214 /// past end of file.
@@ -219,26 +223,26 @@ extension RPCError.Code {
219223 /// ``outOfRange``. We recommend using ``outOfRange`` (the more specific error)
220224 /// when it applies so that callers who are iterating through a space can
221225 /// easily look for an ``outOfRange`` error to detect when they are done.
222- public static let outOfRange = Self ( . outOfRange)
226+ public static let outOfRange = Self ( code : . outOfRange)
223227
224228 /// Operation is not implemented or not supported/enabled in this service.
225- public static let unimplemented = Self ( . unimplemented)
229+ public static let unimplemented = Self ( code : . unimplemented)
226230
227231 /// Internal errors. Means some invariants expected by underlying System has
228232 /// been broken. If you see one of these errors, Something is very broken.
229- public static let internalError = Self ( . internalError)
233+ public static let internalError = Self ( code : . internalError)
230234
231235 /// The service is currently unavailable. This is a most likely a transient
232236 /// condition and may be corrected by retrying with a backoff.
233237 ///
234238 /// See litmus test above for deciding between ``failedPrecondition``, ``aborted``,
235239 /// and ``unavailable``.
236- public static let unavailable = Self ( . unavailable)
240+ public static let unavailable = Self ( code : . unavailable)
237241
238242 /// Unrecoverable data loss or corruption.
239- public static let dataLoss = Self ( . dataLoss)
243+ public static let dataLoss = Self ( code : . dataLoss)
240244
241245 /// The request does not have valid authentication credentials for the
242246 /// operation.
243- public static let unauthenticated = Self ( . unauthenticated)
247+ public static let unauthenticated = Self ( code : . unauthenticated)
244248}
0 commit comments