1 | /** |
---|---|
2 | * Copyright (c) Glow Contributors. See CONTRIBUTORS file. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | |
17 | #include "glow/Runtime/ErrorReporter.h" |
18 | |
19 | #include <algorithm> |
20 | |
21 | namespace glow { |
22 | |
23 | void ErrorReporterRegistry::registerErrorReporter(ErrorReporter *r) { |
24 | reporters_.push_back(r); |
25 | } |
26 | |
27 | void ErrorReporterRegistry::revokeErrorReporter(ErrorReporter *r) { |
28 | reporters_.erase(std::remove(reporters_.begin(), reporters_.end(), r), |
29 | reporters_.end()); |
30 | } |
31 | |
32 | std::shared_ptr<ErrorReporterRegistry> ErrorReporterRegistry::ErrorReporters() { |
33 | static auto reporters = std::make_shared<ErrorReporterRegistry>(); |
34 | return reporters; |
35 | } |
36 | |
37 | detail::GlowError reportOnError(detail::GlowError error) { |
38 | if (error) { |
39 | auto errorValue = error.peekErrorValue(); |
40 | assert(errorValue != nullptr && |
41 | "Error should have a non-null ErrorValue if bool(error) is true"); |
42 | |
43 | auto reporters = ErrorReporterRegistry::ErrorReporters(); |
44 | if (reporters) { |
45 | reporters->report(errorValue->logToString()); |
46 | } |
47 | } |
48 | |
49 | return error; |
50 | } |
51 | |
52 | } // namespace glow |
53 |