blob: 581131e7b5d58b241018cde099aa63c8c553f4ce [file] [log] [blame]
Vitaly Buka4f771532015-08-14 14:58:39 -07001// 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
11#include <chromeos/errors/error.h>
12#include <weave/error.h>
13
14namespace buffet {
15
16template <class Source, class Destination>
17void 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_