blob: 7d3c6ff8ecd3bb4d3029b16d7684511065c697b8 [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
17#define DEBUGD_ADD_ERROR(error, code, message) \
18 brillo::Error::AddTo((error), \
19 FROM_HERE, \
20 brillo::errors::dbus::kDomain, \
21 (code), \
22 (message))
23
24#define DEBUGD_ADD_ERROR_FMT(error, code, format, ...) \
25 brillo::Error::AddToPrintf((error), \
26 FROM_HERE, \
27 brillo::errors::dbus::kDomain, \
28 (code), \
29 format, \
30 ##__VA_ARGS__)
31
32#define DEBUGD_ADD_PERROR(error, code, message) \
33 brillo::Error::AddToPrintf((error), \
34 FROM_HERE, \
35 brillo::errors::dbus::kDomain, \
36 (code), \
37 "%s: %s", \
38 (message), base::safe_strerror(errno).c_str())
39
40#endif // DEBUGD_SRC_ERROR_UTILS_H_