forked from cel-expr/cel-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.cc
More file actions
66 lines (56 loc) · 1.68 KB
/
Copy patherror.cc
File metadata and controls
66 lines (56 loc) · 1.68 KB
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
#include "common/error.h"
#include "google/rpc/code.pb.h"
#include "internal/cel_printer.h"
#include "internal/hash_util.h"
namespace google {
namespace api {
namespace expr {
namespace common {
Error::Error(const google::rpc::Status& error) { errors_.insert(error); }
Error::Error(absl::Span<const google::rpc::Status* const> errors) {
for (const auto* error : errors) {
errors_.insert(*error);
}
}
Error::Error(absl::Span<const google::rpc::Status> errors) {
for (const auto& error : errors) {
errors_.insert(error);
}
}
std::size_t Error::hash_code() const {
std::size_t code = internal::kIntegralTypeOffset;
for (const auto& error : errors_) {
code = internal::MixHashNoOrder(
internal::Hash(error.code(), error.message()), code);
}
return code;
}
const Error::ErrorData& Error::errors() const { return errors_; }
bool Error::operator==(const Error& rhs) const {
if (this == &rhs) {
return true;
}
if (hash_code() != rhs.hash_code() || errors_.size() != rhs.errors_.size()) {
return false;
}
for (const auto& error : errors_) {
if (rhs.errors_.find(error) == rhs.errors_.end()) {
return false;
}
}
return true;
}
std::string Error::ToDebugString() const {
std::multiset<absl::string_view> codes;
for (const auto& error : errors_) {
codes.emplace(
google::rpc::Code_Name(static_cast<google::rpc::Code>(error.code())));
}
internal::VarSequencePrinter<internal::SetJoinPolicy> printer;
return printer("Error", internal::RawString{absl::StrJoin(
codes, internal::SetJoinPolicy::kValueDelim)});
}
} // namespace common
} // namespace expr
} // namespace api
} // namespace google