/proc/self/cwd/runtime/runtime_issue.h
Line | Count | Source |
1 | | // Copyright 2023 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 | | |
15 | | #ifndef THIRD_PARTY_CEL_CPP_RUNTIME_RUNTIME_ISSUE_H_ |
16 | | #define THIRD_PARTY_CEL_CPP_RUNTIME_RUNTIME_ISSUE_H_ |
17 | | |
18 | | #include <utility> |
19 | | |
20 | | #include "absl/status/status.h" |
21 | | |
22 | | namespace cel { |
23 | | |
24 | | // Represents an issue with a given CEL expression. |
25 | | // |
26 | | // The error details are represented as an absl::Status for compatibility |
27 | | // reasons, but users should not depend on this. |
28 | | class RuntimeIssue { |
29 | | public: |
30 | | // Severity of the RuntimeIssue. |
31 | | // |
32 | | // Can be used to determine whether to continue program planning or return |
33 | | // early. |
34 | | enum class Severity { |
35 | | // The issue may lead to runtime errors in evaluation. |
36 | | kWarning = 0, |
37 | | // The expression is invalid or unsupported. |
38 | | kError = 1, |
39 | | // Arbitrary max value above Error. |
40 | | kNotForUseWithExhaustiveSwitchStatements = 15 |
41 | | }; |
42 | | |
43 | | // Code for well-known runtime error kinds. |
44 | | enum class ErrorCode { |
45 | | // Overload not provided for given function call signature. |
46 | | kNoMatchingOverload, |
47 | | // Field access refers to unknown field for given type. |
48 | | kNoSuchField, |
49 | | // Other error outside the canonical set. |
50 | | kOther, |
51 | | }; |
52 | | |
53 | | static RuntimeIssue CreateError(absl::Status status, |
54 | 0 | ErrorCode error_code = ErrorCode::kOther) { |
55 | 0 | return RuntimeIssue(std::move(status), Severity::kError, error_code); |
56 | 0 | } |
57 | | |
58 | | static RuntimeIssue CreateWarning(absl::Status status, |
59 | 122 | ErrorCode error_code = ErrorCode::kOther) { |
60 | 122 | return RuntimeIssue(std::move(status), Severity::kWarning, error_code); |
61 | 122 | } |
62 | | |
63 | | RuntimeIssue(const RuntimeIssue& other) = default; |
64 | | RuntimeIssue& operator=(const RuntimeIssue& other) = default; |
65 | 122 | RuntimeIssue(RuntimeIssue&& other) = default; |
66 | | RuntimeIssue& operator=(RuntimeIssue&& other) = default; |
67 | | |
68 | 122 | Severity severity() const { return severity_; } |
69 | | |
70 | 0 | ErrorCode error_code() const { return error_code_; } |
71 | | |
72 | 122 | const absl::Status& ToStatus() const& { return status_; } |
73 | 0 | absl::Status ToStatus() && { return std::move(status_); } |
74 | | |
75 | | private: |
76 | | RuntimeIssue(absl::Status status, Severity severity, ErrorCode error_code) |
77 | 122 | : status_(std::move(status)), |
78 | 122 | error_code_(error_code), |
79 | 122 | severity_(severity) {} |
80 | | |
81 | | absl::Status status_; |
82 | | ErrorCode error_code_; |
83 | | Severity severity_; |
84 | | }; |
85 | | |
86 | | } // namespace cel |
87 | | |
88 | | #endif // THIRD_PARTY_CEL_CPP_RUNTIME_RUNTIME_ISSUE_H_ |