blob: 4093e8fd199217bd269b5f5c283ea1a0ee908415 [file] [log] [blame]
Eric Carusocc7106c2017-04-27 14:22:42 -07001// Copyright 2017 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 DEBUGD_SRC_ERROR_UTILS_H_
6#define DEBUGD_SRC_ERROR_UTILS_H_
7
8#include <base/location.h>
9#include <base/posix/safe_strerror.h>
10#include <brillo/errors/error.h>
11#include <brillo/errors/error_codes.h>
12
13// These are provided as macros because providing them as functions
14// would cause FROM_HERE to expand to the same value everywhere, which
15// impedes debugging.
16
Tom Hughesd6c2d392020-08-24 18:12:11 -070017#define DEBUGD_ADD_ERROR(error, code, message) \
18 brillo::Error::AddTo((error), FROM_HERE, brillo::errors::dbus::kDomain, \
19 (code), (message))
Eric Carusocc7106c2017-04-27 14:22:42 -070020
Tom Hughesd6c2d392020-08-24 18:12:11 -070021#define DEBUGD_ADD_ERROR_FMT(error, code, format, ...) \
22 brillo::Error::AddToPrintf((error), FROM_HERE, \
23 brillo::errors::dbus::kDomain, (code), format, \
Eric Carusocc7106c2017-04-27 14:22:42 -070024 ##__VA_ARGS__)
25
Tom Hughesd6c2d392020-08-24 18:12:11 -070026#define DEBUGD_ADD_PERROR(error, code, message) \
27 brillo::Error::AddToPrintf((error), FROM_HERE, \
28 brillo::errors::dbus::kDomain, (code), "%s: %s", \
Eric Carusocc7106c2017-04-27 14:22:42 -070029 (message), base::safe_strerror(errno).c_str())
30
31#endif // DEBUGD_SRC_ERROR_UTILS_H_