buffet: Conversion between chromeos::Error and weave::Error

libweave has own error to avoid dependency on libchromeos.

BUG=brillo:1257
TEST=`FEATURES=test emerge-gizmo libweave buffet`
CQ-DEPEND=CL:293615

Change-Id: I64227cdecff29826f95df084a284935ed4ec395a
Reviewed-on: https://chromium-review.googlesource.com/293873
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/weave_error_conversion.h b/buffet/weave_error_conversion.h
new file mode 100644
index 0000000..581131e
--- /dev/null
+++ b/buffet/weave_error_conversion.h
@@ -0,0 +1,34 @@
+// Copyright 2015 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BUFFET_WEAVE_ERROR_CONVERSION_H_
+#define BUFFET_WEAVE_ERROR_CONVERSION_H_
+
+#include <memory>
+#include <string>
+
+#include <chromeos/errors/error.h>
+#include <weave/error.h>
+
+namespace buffet {
+
+template <class Source, class Destination>
+void ConvertError(const Source& source,
+                  std::unique_ptr<Destination>* destination) {
+  const Source* inner_error = source.GetInnerError();
+  if (inner_error)
+    ConvertError(*inner_error, destination);
+
+  const auto& location = source.GetLocation();
+  Destination::AddTo(
+      destination,
+      tracked_objects::Location{
+          location.function_name.c_str(), location.file_name.c_str(),
+          location.line_number, tracked_objects::GetProgramCounter()},
+      source.GetDomain(), source.GetCode(), source.GetMessage());
+}
+
+}  // namespace buffet
+
+#endif  // BUFFET_WEAVE_ERROR_CONVERSION_H_