Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/runtime/internal/issue_collector.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
#ifndef THIRD_PARTY_CEL_CPP_RUNTIME_INTERNAL_ISSUE_COLLECTOR_H_
15
#define THIRD_PARTY_CEL_CPP_RUNTIME_INTERNAL_ISSUE_COLLECTOR_H_
16
17
#include <utility>
18
#include <vector>
19
20
#include "absl/status/status.h"
21
#include "absl/types/span.h"
22
#include "runtime/runtime_issue.h"
23
24
namespace cel::runtime_internal {
25
26
// IssueCollector collects issues and reports absl::Status according to the
27
// configured severity limit.
28
class IssueCollector {
29
 public:
30
  // Args:
31
  //  severity: inclusive limit for issues to return as non-ok absl::Status.
32
  explicit IssueCollector(RuntimeIssue::Severity severity_limit)
33
10.3k
      : severity_limit_(severity_limit) {}
34
35
  // move-only.
36
  IssueCollector(const IssueCollector&) = delete;
37
  IssueCollector& operator=(const IssueCollector&) = delete;
38
  IssueCollector(IssueCollector&&) = default;
39
  IssueCollector& operator=(IssueCollector&&) = default;
40
41
  // Collect an Issue.
42
  // Returns a status according to the IssueCollector's policy and the given
43
  // Issue.
44
  // The Issue is always added to issues, regardless of whether AddIssue returns
45
  // a non-ok status.
46
122
  absl::Status AddIssue(RuntimeIssue issue) {
47
122
    issues_.push_back(std::move(issue));
48
122
    if (issues_.back().severity() >= severity_limit_) {
49
122
      return issues_.back().ToStatus();
50
122
    }
51
0
    return absl::OkStatus();
52
122
  }
53
54
0
  absl::Span<const RuntimeIssue> issues() const { return issues_; }
55
0
  std::vector<RuntimeIssue> ExtractIssues() { return std::move(issues_); }
56
57
 private:
58
  RuntimeIssue::Severity severity_limit_;
59
  std::vector<RuntimeIssue> issues_;
60
};
61
62
}  // namespace cel::runtime_internal
63
64
#endif  // THIRD_PARTY_CEL_CPP_RUNTIME_INTERNAL_ISSUE_COLLECTOR_H_