Vitaly Buka | 4f77153 | 2015-08-14 14:58:39 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BUFFET_WEAVE_ERROR_CONVERSION_H_ |
| 6 | #define BUFFET_WEAVE_ERROR_CONVERSION_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame^] | 11 | #include <brillo/errors/error.h> |
Vitaly Buka | 4f77153 | 2015-08-14 14:58:39 -0700 | [diff] [blame] | 12 | #include <weave/error.h> |
| 13 | |
| 14 | namespace buffet { |
| 15 | |
| 16 | template <class Source, class Destination> |
| 17 | void ConvertError(const Source& source, |
| 18 | std::unique_ptr<Destination>* destination) { |
| 19 | const Source* inner_error = source.GetInnerError(); |
| 20 | if (inner_error) |
| 21 | ConvertError(*inner_error, destination); |
| 22 | |
| 23 | const auto& location = source.GetLocation(); |
| 24 | Destination::AddTo( |
| 25 | destination, |
| 26 | tracked_objects::Location{ |
| 27 | location.function_name.c_str(), location.file_name.c_str(), |
| 28 | location.line_number, tracked_objects::GetProgramCounter()}, |
| 29 | source.GetDomain(), source.GetCode(), source.GetMessage()); |
| 30 | } |
| 31 | |
| 32 | } // namespace buffet |
| 33 | |
| 34 | #endif // BUFFET_WEAVE_ERROR_CONVERSION_H_ |