|
| 1 | +/* |
| 2 | + * Copyright 2016, gRPC Authors All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +import Foundation |
| 17 | + |
| 18 | +/// Status codes for gRPC operations (replicated from status_code_enum.h) |
| 19 | +public enum StatusCode: Int { |
| 20 | + /// Not an error; returned on success. |
| 21 | + case ok = 0 |
| 22 | + |
| 23 | + /// The operation was cancelled (typically by the caller). |
| 24 | + case cancelled = 1 |
| 25 | + |
| 26 | + /// Unknown error. An example of where this error may be returned is if a |
| 27 | + /// Status value received from another address space belongs to an error-space |
| 28 | + /// that is not known in this address space. Also errors raised by APIs that |
| 29 | + /// do not return enough error information may be converted to this error. |
| 30 | + case unknown = 2 |
| 31 | + |
| 32 | + /// Client specified an invalid argument. Note that this differs from |
| 33 | + /// FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments that are |
| 34 | + /// problematic regardless of the state of the system (e.g., a malformed file |
| 35 | + /// name). |
| 36 | + case invalidArgument = 3 |
| 37 | + |
| 38 | + /// Deadline expired before operation could complete. For operations that |
| 39 | + /// change the state of the system, this error may be returned even if the |
| 40 | + /// operation has completed successfully. For example, a successful response |
| 41 | + /// from a server could have been delayed long enough for the deadline to |
| 42 | + /// expire. |
| 43 | + case deadlineExceeded = 4 |
| 44 | + |
| 45 | + /// Some requested entity (e.g., file or directory) was not found. |
| 46 | + case notFound = 5 |
| 47 | + |
| 48 | + /// Some entity that we attempted to create (e.g., file or directory) already |
| 49 | + /// exists. |
| 50 | + case alreadyExists = 6 |
| 51 | + |
| 52 | + /// The caller does not have permission to execute the specified operation. |
| 53 | + /// PERMISSION_DENIED must not be used for rejections caused by exhausting |
| 54 | + /// some resource (use RESOURCE_EXHAUSTED instead for those errors). |
| 55 | + /// PERMISSION_DENIED must not be used if the caller can not be identified |
| 56 | + /// (use UNAUTHENTICATED instead for those errors). |
| 57 | + case permissionDenied = 7 |
| 58 | + |
| 59 | + /// The request does not have valid authentication credentials for the |
| 60 | + /// operation. |
| 61 | + case unauthenticated = 16 |
| 62 | + |
| 63 | + /// Some resource has been exhausted, perhaps a per-user quota, or perhaps the |
| 64 | + /// entire file system is out of space. |
| 65 | + case resourceExhausted = 8 |
| 66 | + |
| 67 | + /// Operation was rejected because the system is not in a state required for |
| 68 | + /// the operation's execution. For example, directory to be deleted may be |
| 69 | + /// non-empty, an rmdir operation is applied to a non-directory, etc. |
| 70 | + /// |
| 71 | + /// A litmus test that may help a service implementor in deciding |
| 72 | + /// between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE: |
| 73 | + /// (a) Use UNAVAILABLE if the client can retry just the failing call. |
| 74 | + /// (b) Use ABORTED if the client should retry at a higher-level |
| 75 | + /// (e.g., restarting a read-modify-write sequence). |
| 76 | + /// (c) Use FAILED_PRECONDITION if the client should not retry until |
| 77 | + /// the system state has been explicitly fixed. E.g., if an "rmdir" |
| 78 | + /// fails because the directory is non-empty, FAILED_PRECONDITION |
| 79 | + /// should be returned since the client should not retry unless |
| 80 | + /// they have first fixed up the directory by deleting files from it. |
| 81 | + /// (d) Use FAILED_PRECONDITION if the client performs conditional |
| 82 | + /// REST Get/Update/Delete on a resource and the resource on the |
| 83 | + /// server does not match the condition. E.g., conflicting |
| 84 | + /// read-modify-write on the same resource. |
| 85 | + case failedPrecondition = 9 |
| 86 | + |
| 87 | + /// The operation was aborted, typically due to a concurrency issue like |
| 88 | + /// sequencer check failures, transaction aborts, etc. |
| 89 | + /// |
| 90 | + /// See litmus test above for deciding between FAILED_PRECONDITION, ABORTED, |
| 91 | + /// and UNAVAILABLE. |
| 92 | + case aborted = 10 |
| 93 | + |
| 94 | + /// Operation was attempted past the valid range. E.g., seeking or reading |
| 95 | + /// past end of file. |
| 96 | + /// |
| 97 | + /// Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed |
| 98 | + /// if the system state changes. For example, a 32-bit file system will |
| 99 | + /// generate INVALID_ARGUMENT if asked to read at an offset that is not in the |
| 100 | + /// range [0,2^32-1], but it will generate OUT_OF_RANGE if asked to read from |
| 101 | + /// an offset past the current file size. |
| 102 | + /// |
| 103 | + /// There is a fair bit of overlap between FAILED_PRECONDITION and |
| 104 | + /// OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific error) |
| 105 | + /// when it applies so that callers who are iterating through a space can |
| 106 | + /// easily look for an OUT_OF_RANGE error to detect when they are done. |
| 107 | + case outOfRange = 11 |
| 108 | + |
| 109 | + /// Operation is not implemented or not supported/enabled in this service. |
| 110 | + case unimplemented = 12 |
| 111 | + |
| 112 | + /// Internal errors. Means some invariants expected by underlying System has |
| 113 | + /// been broken. If you see one of these errors, Something is very broken. |
| 114 | + case internalError = 13 |
| 115 | + |
| 116 | + /// The service is currently unavailable. This is a most likely a transient |
| 117 | + /// condition and may be corrected by retrying with a backoff. |
| 118 | + /// |
| 119 | + /// See litmus test above for deciding between FAILED_PRECONDITION, ABORTED, |
| 120 | + /// and UNAVAILABLE. |
| 121 | + case unavailable = 14 |
| 122 | + |
| 123 | + /// Unrecoverable data loss or corruption. |
| 124 | + case dataLoss = 15 |
| 125 | + |
| 126 | + /// Force users to include a default branch: |
| 127 | + case doNotUse = -1 |
| 128 | +} |
0 commit comments