forked from google/cel-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status_util.cc
75 lines (60 loc) · 2.31 KB
/
status_util.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "internal/status_util.h"
#include "google/rpc/code.pb.h"
#include "absl/strings/str_cat.h"
namespace google {
namespace api {
namespace expr {
namespace internal {
namespace {
google::rpc::Status NewStatus(google::rpc::Code code,
absl::string_view message) {
google::rpc::Status error;
error.set_code(code);
error.set_message(std::string(message));
return error;
}
} // namespace
google::rpc::Status InvalidArgumentError(absl::string_view message) {
return NewStatus(google::rpc::Code::INVALID_ARGUMENT, message);
}
google::rpc::Status NotFoundError(absl::string_view message) {
return NewStatus(google::rpc::Code::NOT_FOUND, message);
}
google::rpc::Status UnimplementedError(absl::string_view message) {
return NewStatus(google::rpc::Code::UNIMPLEMENTED, message);
}
google::rpc::Status OutOfRangeError(absl::string_view message) {
return NewStatus(google::rpc::Code::OUT_OF_RANGE, message);
}
google::rpc::Status CancelledError() {
return NewStatus(google::rpc::Code::CANCELLED, "");
}
google::rpc::Status InternalError(absl::string_view message) {
return NewStatus(google::rpc::Code::INTERNAL, message);
}
google::rpc::Status OutOfRangeError(size_t index, size_t size) {
return OutOfRangeError(absl::StrCat(index, " exceeds size ", size));
}
google::rpc::Status NoSuchCall(absl::string_view call,
absl::string_view full_type_name) {
return NotFoundError(absl::StrCat(call, " not found in ", full_type_name));
}
google::rpc::Status NoSuchMember(absl::string_view member,
absl::string_view full_type_name) {
return NotFoundError(absl::StrCat(member, " not found in ", full_type_name));
}
google::rpc::Status UnknownType(absl::string_view full_type_name) {
return InvalidArgumentError(absl::StrCat("Unknown type: ", full_type_name));
}
google::rpc::Status ParseError(absl::string_view full_type_name) {
return InvalidArgumentError(absl::StrCat("Could not parse ", full_type_name));
}
google::rpc::Status UnexpectedType(absl::string_view full_type_name,
absl::string_view context) {
return InvalidArgumentError(
absl::StrCat("Unexpected type, ", full_type_name, ", in ", context));
}
} // namespace internal
} // namespace expr
} // namespace api
} // namespace google