|
@@ -27,13 +27,12 @@
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
+
|
|
#ifndef GOOGLE_PROTOBUF_STUBS_STATUS_H_
|
|
#ifndef GOOGLE_PROTOBUF_STUBS_STATUS_H_
|
|
#define GOOGLE_PROTOBUF_STUBS_STATUS_H_
|
|
#define GOOGLE_PROTOBUF_STUBS_STATUS_H_
|
|
|
|
|
|
-#include <iosfwd>
|
|
|
|
#include <string>
|
|
#include <string>
|
|
|
|
|
|
-#include <google/protobuf/stubs/common.h>
|
|
|
|
#include <google/protobuf/stubs/stringpiece.h>
|
|
#include <google/protobuf/stubs/stringpiece.h>
|
|
|
|
|
|
#include <google/protobuf/port_def.inc>
|
|
#include <google/protobuf/port_def.inc>
|
|
@@ -41,28 +40,28 @@
|
|
namespace google {
|
|
namespace google {
|
|
namespace protobuf {
|
|
namespace protobuf {
|
|
namespace util {
|
|
namespace util {
|
|
-namespace error {
|
|
|
|
|
|
+namespace status_internal {
|
|
|
|
+
|
|
// These values must match error codes defined in google/rpc/code.proto.
|
|
// These values must match error codes defined in google/rpc/code.proto.
|
|
-enum Code {
|
|
|
|
- OK = 0,
|
|
|
|
- CANCELLED = 1,
|
|
|
|
- UNKNOWN = 2,
|
|
|
|
- INVALID_ARGUMENT = 3,
|
|
|
|
- DEADLINE_EXCEEDED = 4,
|
|
|
|
- NOT_FOUND = 5,
|
|
|
|
- ALREADY_EXISTS = 6,
|
|
|
|
- PERMISSION_DENIED = 7,
|
|
|
|
- UNAUTHENTICATED = 16,
|
|
|
|
- RESOURCE_EXHAUSTED = 8,
|
|
|
|
- FAILED_PRECONDITION = 9,
|
|
|
|
- ABORTED = 10,
|
|
|
|
- OUT_OF_RANGE = 11,
|
|
|
|
- UNIMPLEMENTED = 12,
|
|
|
|
- INTERNAL = 13,
|
|
|
|
- UNAVAILABLE = 14,
|
|
|
|
- DATA_LOSS = 15,
|
|
|
|
|
|
+enum class StatusCode : int {
|
|
|
|
+ kOk = 0,
|
|
|
|
+ kCancelled = 1,
|
|
|
|
+ kUnknown = 2,
|
|
|
|
+ kInvalidArgument = 3,
|
|
|
|
+ kDeadlineExceeded = 4,
|
|
|
|
+ kNotFound = 5,
|
|
|
|
+ kAlreadyExists = 6,
|
|
|
|
+ kPermissionDenied = 7,
|
|
|
|
+ kUnauthenticated = 16,
|
|
|
|
+ kResourceExhausted = 8,
|
|
|
|
+ kFailedPrecondition = 9,
|
|
|
|
+ kAborted = 10,
|
|
|
|
+ kOutOfRange = 11,
|
|
|
|
+ kUnimplemented = 12,
|
|
|
|
+ kInternal = 13,
|
|
|
|
+ kUnavailable = 14,
|
|
|
|
+ kDataLoss = 15,
|
|
};
|
|
};
|
|
-} // namespace error
|
|
|
|
|
|
|
|
class PROTOBUF_EXPORT Status {
|
|
class PROTOBUF_EXPORT Status {
|
|
public:
|
|
public:
|
|
@@ -71,9 +70,9 @@ class PROTOBUF_EXPORT Status {
|
|
|
|
|
|
// Create a status in the canonical error space with the specified
|
|
// Create a status in the canonical error space with the specified
|
|
// code, and error message. If "code == 0", error_message is
|
|
// code, and error message. If "code == 0", error_message is
|
|
- // ignored and a Status object identical to Status::OK is
|
|
|
|
|
|
+ // ignored and a Status object identical to Status::kOk is
|
|
// constructed.
|
|
// constructed.
|
|
- Status(error::Code error_code, StringPiece error_message);
|
|
|
|
|
|
+ Status(StatusCode error_code, StringPiece error_message);
|
|
Status(const Status&);
|
|
Status(const Status&);
|
|
Status& operator=(const Status& x);
|
|
Status& operator=(const Status& x);
|
|
~Status() {}
|
|
~Status() {}
|
|
@@ -85,17 +84,11 @@ class PROTOBUF_EXPORT Status {
|
|
|
|
|
|
// Accessor
|
|
// Accessor
|
|
bool ok() const {
|
|
bool ok() const {
|
|
- return error_code_ == error::OK;
|
|
|
|
|
|
+ return error_code_ == StatusCode::kOk;
|
|
}
|
|
}
|
|
- int error_code() const {
|
|
|
|
|
|
+ StatusCode code() const {
|
|
return error_code_;
|
|
return error_code_;
|
|
}
|
|
}
|
|
- error::Code code() const {
|
|
|
|
- return error_code_;
|
|
|
|
- }
|
|
|
|
- StringPiece error_message() const {
|
|
|
|
- return error_message_;
|
|
|
|
- }
|
|
|
|
StringPiece message() const {
|
|
StringPiece message() const {
|
|
return error_message_;
|
|
return error_message_;
|
|
}
|
|
}
|
|
@@ -109,13 +102,29 @@ class PROTOBUF_EXPORT Status {
|
|
std::string ToString() const;
|
|
std::string ToString() const;
|
|
|
|
|
|
private:
|
|
private:
|
|
- error::Code error_code_;
|
|
|
|
|
|
+ StatusCode error_code_;
|
|
std::string error_message_;
|
|
std::string error_message_;
|
|
};
|
|
};
|
|
|
|
|
|
// Prints a human-readable representation of 'x' to 'os'.
|
|
// Prints a human-readable representation of 'x' to 'os'.
|
|
PROTOBUF_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x);
|
|
PROTOBUF_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x);
|
|
|
|
|
|
|
|
+} // namespace status_internal
|
|
|
|
+
|
|
|
|
+using ::google::protobuf::util::status_internal::Status;
|
|
|
|
+using ::google::protobuf::util::status_internal::StatusCode;
|
|
|
|
+
|
|
|
|
+namespace error {
|
|
|
|
+
|
|
|
|
+// TODO(yannic): Remove these.
|
|
|
|
+constexpr StatusCode OK = StatusCode::kOk;
|
|
|
|
+constexpr StatusCode CANCELLED = StatusCode::kCancelled;
|
|
|
|
+constexpr StatusCode UNKNOWN = StatusCode::kUnknown;
|
|
|
|
+constexpr StatusCode INVALID_ARGUMENT = StatusCode::kInvalidArgument;
|
|
|
|
+constexpr StatusCode NOT_FOUND = StatusCode::kNotFound;
|
|
|
|
+constexpr StatusCode INTERNAL = StatusCode::kInternal;
|
|
|
|
+
|
|
|
|
+} // namespace error
|
|
} // namespace util
|
|
} // namespace util
|
|
} // namespace protobuf
|
|
} // namespace protobuf
|
|
} // namespace google
|
|
} // namespace google
|