/proc/self/cwd/runtime/internal/errors.cc
Line | Count | Source |
1 | | // Copyright 2022 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | #include "runtime/internal/errors.h" |
15 | | |
16 | | #include "absl/status/status.h" |
17 | | #include "absl/strings/cord.h" |
18 | | #include "absl/strings/str_cat.h" |
19 | | #include "absl/strings/string_view.h" |
20 | | |
21 | | namespace cel::runtime_internal { |
22 | | |
23 | 0 | const absl::Status* DurationOverflowError() { |
24 | 0 | static const auto* const kDurationOverflow = new absl::Status( |
25 | 0 | absl::StatusCode::kInvalidArgument, "Duration is out of range"); |
26 | 0 | return kDurationOverflow; |
27 | 0 | } |
28 | | |
29 | 3.16k | absl::Status CreateNoSuchKeyError(absl::string_view key) { |
30 | 3.16k | return absl::NotFoundError(absl::StrCat(kErrNoSuchKey, " : ", key)); |
31 | 3.16k | } |
32 | | |
33 | 6.93k | absl::Status CreateNoMatchingOverloadError(absl::string_view fn) { |
34 | 6.93k | return absl::UnknownError( |
35 | 6.93k | absl::StrCat(kErrNoMatchingOverload, fn.empty() ? "" : " : ", fn)); |
36 | 6.93k | } |
37 | | |
38 | 284 | absl::Status CreateNoSuchFieldError(absl::string_view field) { |
39 | 284 | return absl::Status( |
40 | 284 | absl::StatusCode::kNotFound, |
41 | 284 | absl::StrCat(kErrNoSuchField, field.empty() ? "" : " : ", field)); |
42 | 284 | } |
43 | | |
44 | | absl::Status CreateMissingAttributeError( |
45 | 0 | absl::string_view missing_attribute_path) { |
46 | 0 | absl::Status result = absl::InvalidArgumentError( |
47 | 0 | absl::StrCat(kErrMissingAttribute, missing_attribute_path)); |
48 | 0 | result.SetPayload(kPayloadUrlMissingAttributePath, |
49 | 0 | absl::Cord(missing_attribute_path)); |
50 | 0 | return result; |
51 | 0 | } |
52 | | |
53 | 0 | absl::Status CreateInvalidMapKeyTypeError(absl::string_view key_type) { |
54 | 0 | return absl::InvalidArgumentError( |
55 | 0 | absl::StrCat("Invalid map key type: '", key_type, "'")); |
56 | 0 | } |
57 | | |
58 | 0 | absl::Status CreateUnknownFunctionResultError(absl::string_view help_message) { |
59 | 0 | absl::Status result = absl::UnavailableError( |
60 | 0 | absl::StrCat("Unknown function result: ", help_message)); |
61 | 0 | result.SetPayload(kPayloadUrlUnknownFunctionResult, absl::Cord("true")); |
62 | 0 | return result; |
63 | 0 | } |
64 | | |
65 | 54.4k | absl::Status CreateError(absl::string_view message, absl::StatusCode code) { |
66 | 54.4k | return absl::Status(code, message); |
67 | 54.4k | } |
68 | | |
69 | | } // namespace cel::runtime_internal |