Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 1 | // 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 Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 17 | #define DEBUGD_ADD_ERROR(error, code, message) \ |
| 18 | brillo::Error::AddTo((error), FROM_HERE, brillo::errors::dbus::kDomain, \ |
| 19 | (code), (message)) |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 20 | |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 21 | #define DEBUGD_ADD_ERROR_FMT(error, code, format, ...) \ |
| 22 | brillo::Error::AddToPrintf((error), FROM_HERE, \ |
| 23 | brillo::errors::dbus::kDomain, (code), format, \ |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 24 | ##__VA_ARGS__) |
| 25 | |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 26 | #define DEBUGD_ADD_PERROR(error, code, message) \ |
| 27 | brillo::Error::AddToPrintf((error), FROM_HERE, \ |
| 28 | brillo::errors::dbus::kDomain, (code), "%s: %s", \ |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 29 | (message), base::safe_strerror(errno).c_str()) |
| 30 | |
| 31 | #endif // DEBUGD_SRC_ERROR_UTILS_H_ |