Luiz Capitulino | 9f9daf9 | 2009-11-18 23:05:30 -0200 | [diff] [blame] | 1 | /* |
Luiz Capitulino | 41836a9 | 2010-05-12 16:34:42 -0300 | [diff] [blame] | 2 | * QError Module |
Luiz Capitulino | 9f9daf9 | 2009-11-18 23:05:30 -0200 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2009 Red Hat Inc. |
| 5 | * |
| 6 | * Authors: |
| 7 | * Luiz Capitulino <lcapitulino@redhat.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. |
| 10 | * See the COPYING.LIB file in the top-level directory. |
| 11 | */ |
| 12 | #ifndef QERROR_H |
| 13 | #define QERROR_H |
| 14 | |
| 15 | #include "qdict.h" |
Markus Armbruster | 77e595e | 2009-12-07 21:37:16 +0100 | [diff] [blame] | 16 | #include "qstring.h" |
Markus Armbruster | 827b081 | 2010-02-18 19:46:49 +0100 | [diff] [blame] | 17 | #include "qemu-error.h" |
Anthony Liguori | 2a82d93 | 2011-09-02 12:34:45 -0500 | [diff] [blame] | 18 | #include "error.h" |
Luiz Capitulino | 9f9daf9 | 2009-11-18 23:05:30 -0200 | [diff] [blame] | 19 | #include <stdarg.h> |
| 20 | |
| 21 | typedef struct QErrorStringTable { |
| 22 | const char *desc; |
| 23 | const char *error_fmt; |
| 24 | } QErrorStringTable; |
| 25 | |
| 26 | typedef struct QError { |
| 27 | QObject_HEAD; |
| 28 | QDict *error; |
Markus Armbruster | 827b081 | 2010-02-18 19:46:49 +0100 | [diff] [blame] | 29 | Location loc; |
Luiz Capitulino | 9f9daf9 | 2009-11-18 23:05:30 -0200 | [diff] [blame] | 30 | int linenr; |
| 31 | const char *file; |
| 32 | const char *func; |
| 33 | const QErrorStringTable *entry; |
| 34 | } QError; |
| 35 | |
| 36 | QError *qerror_new(void); |
| 37 | QError *qerror_from_info(const char *file, int linenr, const char *func, |
Stefan Weil | 8b7968f | 2010-09-23 21:28:05 +0200 | [diff] [blame] | 38 | const char *fmt, va_list *va) GCC_FMT_ATTR(4, 0); |
Markus Armbruster | 77e595e | 2009-12-07 21:37:16 +0100 | [diff] [blame] | 39 | QString *qerror_human(const QError *qerror); |
Markus Armbruster | 827b081 | 2010-02-18 19:46:49 +0100 | [diff] [blame] | 40 | void qerror_print(QError *qerror); |
Markus Armbruster | 0167f77 | 2010-03-22 10:29:05 +0100 | [diff] [blame] | 41 | void qerror_report_internal(const char *file, int linenr, const char *func, |
Stefan Weil | e5924d8 | 2010-09-23 21:28:03 +0200 | [diff] [blame] | 42 | const char *fmt, ...) GCC_FMT_ATTR(4, 5); |
Anthony Liguori | 2a82d93 | 2011-09-02 12:34:45 -0500 | [diff] [blame] | 43 | void qerror_report_err(Error *err); |
Luiz Capitulino | 87c2f59 | 2011-06-01 12:14:48 -0500 | [diff] [blame] | 44 | QString *qerror_format(const char *fmt, QDict *error); |
Markus Armbruster | 0167f77 | 2010-03-22 10:29:05 +0100 | [diff] [blame] | 45 | #define qerror_report(fmt, ...) \ |
| 46 | qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__) |
Luiz Capitulino | 9f9daf9 | 2009-11-18 23:05:30 -0200 | [diff] [blame] | 47 | QError *qobject_to_qerror(const QObject *obj); |
| 48 | |
| 49 | /* |
| 50 | * QError class list |
Markus Armbruster | 9d494c4 | 2010-03-25 17:22:30 +0100 | [diff] [blame] | 51 | * Please keep the definitions in alphabetical order. |
| 52 | * Use "grep '^#define QERR_' qerror.h | sort -c" to check. |
Luiz Capitulino | 9f9daf9 | 2009-11-18 23:05:30 -0200 | [diff] [blame] | 53 | */ |
Markus Armbruster | 56e9f56 | 2010-02-19 19:52:45 +0100 | [diff] [blame] | 54 | #define QERR_BAD_BUS_FOR_DEVICE \ |
| 55 | "{ 'class': 'BadBusForDevice', 'data': { 'device': %s, 'bad_bus_type': %s } }" |
| 56 | |
Markus Armbruster | 7bbd823 | 2010-02-19 18:05:39 +0100 | [diff] [blame] | 57 | #define QERR_BUS_NOT_FOUND \ |
| 58 | "{ 'class': 'BusNotFound', 'data': { 'bus': %s } }" |
| 59 | |
Markus Armbruster | 8eae73b | 2010-02-19 19:53:36 +0100 | [diff] [blame] | 60 | #define QERR_BUS_NO_HOTPLUG \ |
| 61 | "{ 'class': 'BusNoHotplug', 'data': { 'bus': %s } }" |
| 62 | |
Luiz Capitulino | 4b9d468 | 2009-11-26 22:58:57 -0200 | [diff] [blame] | 63 | #define QERR_COMMAND_NOT_FOUND \ |
Markus Armbruster | e16a181 | 2009-12-07 21:37:02 +0100 | [diff] [blame] | 64 | "{ 'class': 'CommandNotFound', 'data': { 'name': %s } }" |
Luiz Capitulino | 4b9d468 | 2009-11-26 22:58:57 -0200 | [diff] [blame] | 65 | |
Luiz Capitulino | 0df37c4 | 2009-12-07 21:36:59 +0100 | [diff] [blame] | 66 | #define QERR_DEVICE_ENCRYPTED \ |
Markus Armbruster | e16a181 | 2009-12-07 21:37:02 +0100 | [diff] [blame] | 67 | "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }" |
Luiz Capitulino | 9f9daf9 | 2009-11-18 23:05:30 -0200 | [diff] [blame] | 68 | |
Markus Armbruster | 4d9a1a1 | 2010-02-19 19:53:54 +0100 | [diff] [blame] | 69 | #define QERR_DEVICE_INIT_FAILED \ |
| 70 | "{ 'class': 'DeviceInitFailed', 'data': { 'device': %s } }" |
| 71 | |
Markus Armbruster | 5124eb5 | 2010-03-25 17:22:39 +0100 | [diff] [blame] | 72 | #define QERR_DEVICE_IN_USE \ |
| 73 | "{ 'class': 'DeviceInUse', 'data': { 'device': %s } }" |
| 74 | |
Markus Armbruster | fc5469d | 2010-02-19 17:42:46 +0100 | [diff] [blame] | 75 | #define QERR_DEVICE_LOCKED \ |
Markus Armbruster | b086838 | 2009-12-07 21:37:03 +0100 | [diff] [blame] | 76 | "{ 'class': 'DeviceLocked', 'data': { 'device': %s } }" |
| 77 | |
Markus Armbruster | 1ae7871 | 2010-02-19 18:05:59 +0100 | [diff] [blame] | 78 | #define QERR_DEVICE_MULTIPLE_BUSSES \ |
| 79 | "{ 'class': 'DeviceMultipleBusses', 'data': { 'device': %s } }" |
| 80 | |
Luiz Capitulino | 055f612 | 2009-11-18 23:05:34 -0200 | [diff] [blame] | 81 | #define QERR_DEVICE_NOT_ACTIVE \ |
Markus Armbruster | e16a181 | 2009-12-07 21:37:02 +0100 | [diff] [blame] | 82 | "{ 'class': 'DeviceNotActive', 'data': { 'device': %s } }" |
| 83 | |
Markus Armbruster | 9d494c4 | 2010-03-25 17:22:30 +0100 | [diff] [blame] | 84 | #define QERR_DEVICE_NOT_ENCRYPTED \ |
| 85 | "{ 'class': 'DeviceNotEncrypted', 'data': { 'device': %s } }" |
| 86 | |
Markus Armbruster | e16a181 | 2009-12-07 21:37:02 +0100 | [diff] [blame] | 87 | #define QERR_DEVICE_NOT_FOUND \ |
| 88 | "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }" |
Luiz Capitulino | 055f612 | 2009-11-18 23:05:34 -0200 | [diff] [blame] | 89 | |
Markus Armbruster | 5cfe026 | 2009-12-07 21:37:04 +0100 | [diff] [blame] | 90 | #define QERR_DEVICE_NOT_REMOVABLE \ |
| 91 | "{ 'class': 'DeviceNotRemovable', 'data': { 'device': %s } }" |
| 92 | |
Markus Armbruster | 07574ba | 2010-02-19 18:06:18 +0100 | [diff] [blame] | 93 | #define QERR_DEVICE_NO_BUS \ |
| 94 | "{ 'class': 'DeviceNoBus', 'data': { 'device': %s } }" |
| 95 | |
Gerd Hoffmann | 180c22e | 2011-01-06 15:14:37 +0100 | [diff] [blame] | 96 | #define QERR_DEVICE_NO_HOTPLUG \ |
| 97 | "{ 'class': 'DeviceNoHotplug', 'data': { 'device': %s } }" |
| 98 | |
Markus Armbruster | 7bc8401 | 2010-03-25 17:22:31 +0100 | [diff] [blame] | 99 | #define QERR_DUPLICATE_ID \ |
| 100 | "{ 'class': 'DuplicateId', 'data': { 'id': %s, 'object': %s } }" |
| 101 | |
Markus Armbruster | c7c338c | 2009-12-07 21:37:10 +0100 | [diff] [blame] | 102 | #define QERR_FD_NOT_FOUND \ |
Markus Armbruster | bd9d306 | 2009-12-08 13:33:54 +0100 | [diff] [blame] | 103 | "{ 'class': 'FdNotFound', 'data': { 'name': %s } }" |
Markus Armbruster | c7c338c | 2009-12-07 21:37:10 +0100 | [diff] [blame] | 104 | |
Markus Armbruster | 41471a2 | 2009-12-07 21:37:12 +0100 | [diff] [blame] | 105 | #define QERR_FD_NOT_SUPPLIED \ |
Markus Armbruster | bd9d306 | 2009-12-08 13:33:54 +0100 | [diff] [blame] | 106 | "{ 'class': 'FdNotSupplied', 'data': {} }" |
Markus Armbruster | 41471a2 | 2009-12-07 21:37:12 +0100 | [diff] [blame] | 107 | |
Markus Armbruster | 17901e7 | 2009-12-07 21:37:06 +0100 | [diff] [blame] | 108 | #define QERR_INVALID_BLOCK_FORMAT \ |
| 109 | "{ 'class': 'InvalidBlockFormat', 'data': { 'name': %s } }" |
| 110 | |
Markus Armbruster | 7a046f5 | 2009-12-07 21:37:13 +0100 | [diff] [blame] | 111 | #define QERR_INVALID_PARAMETER \ |
Markus Armbruster | bd9d306 | 2009-12-08 13:33:54 +0100 | [diff] [blame] | 112 | "{ 'class': 'InvalidParameter', 'data': { 'name': %s } }" |
Markus Armbruster | 7a046f5 | 2009-12-07 21:37:13 +0100 | [diff] [blame] | 113 | |
Luiz Capitulino | 4b9d468 | 2009-11-26 22:58:57 -0200 | [diff] [blame] | 114 | #define QERR_INVALID_PARAMETER_TYPE \ |
Markus Armbruster | e16a181 | 2009-12-07 21:37:02 +0100 | [diff] [blame] | 115 | "{ 'class': 'InvalidParameterType', 'data': { 'name': %s,'expected': %s } }" |
Luiz Capitulino | 4b9d468 | 2009-11-26 22:58:57 -0200 | [diff] [blame] | 116 | |
Markus Armbruster | 985a3e5 | 2010-03-25 17:22:33 +0100 | [diff] [blame] | 117 | #define QERR_INVALID_PARAMETER_VALUE \ |
| 118 | "{ 'class': 'InvalidParameterValue', 'data': { 'name': %s, 'expected': %s } }" |
| 119 | |
Luiz Capitulino | f6d855c | 2009-12-04 15:24:08 -0200 | [diff] [blame] | 120 | #define QERR_INVALID_PASSWORD \ |
Markus Armbruster | e16a181 | 2009-12-07 21:37:02 +0100 | [diff] [blame] | 121 | "{ 'class': 'InvalidPassword', 'data': {} }" |
Luiz Capitulino | 4b9d468 | 2009-11-26 22:58:57 -0200 | [diff] [blame] | 122 | |
| 123 | #define QERR_JSON_PARSING \ |
Markus Armbruster | e16a181 | 2009-12-07 21:37:02 +0100 | [diff] [blame] | 124 | "{ 'class': 'JSONParsing', 'data': {} }" |
| 125 | |
Anthony Liguori | ef749d0 | 2011-06-01 12:14:50 -0500 | [diff] [blame] | 126 | #define QERR_JSON_PARSE_ERROR \ |
| 127 | "{ 'class': 'JSONParseError', 'data': { 'message': %s } }" |
| 128 | |
Michael Roth | c40cc0a | 2011-07-19 14:50:33 -0500 | [diff] [blame] | 129 | #define QERR_BUFFER_OVERRUN \ |
| 130 | "{ 'class': 'BufferOverrun', 'data': {} }" |
| 131 | |
Markus Armbruster | e16a181 | 2009-12-07 21:37:02 +0100 | [diff] [blame] | 132 | #define QERR_KVM_MISSING_CAP \ |
| 133 | "{ 'class': 'KVMMissingCap', 'data': { 'capability': %s, 'feature': %s } }" |
| 134 | |
Amit Shah | 8e84865 | 2010-07-27 15:49:19 +0530 | [diff] [blame] | 135 | #define QERR_MIGRATION_EXPECTED \ |
| 136 | "{ 'class': 'MigrationExpected', 'data': {} }" |
| 137 | |
Markus Armbruster | e16a181 | 2009-12-07 21:37:02 +0100 | [diff] [blame] | 138 | #define QERR_MISSING_PARAMETER \ |
| 139 | "{ 'class': 'MissingParameter', 'data': { 'name': %s } }" |
| 140 | |
Markus Armbruster | fab5767 | 2010-02-19 19:54:06 +0100 | [diff] [blame] | 141 | #define QERR_NO_BUS_FOR_DEVICE \ |
| 142 | "{ 'class': 'NoBusForDevice', 'data': { 'device': %s, 'bus': %s } }" |
| 143 | |
Markus Armbruster | fc5469d | 2010-02-19 17:42:46 +0100 | [diff] [blame] | 144 | #define QERR_OPEN_FILE_FAILED \ |
| 145 | "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }" |
| 146 | |
Markus Armbruster | c58a35f | 2010-02-19 13:11:41 +0100 | [diff] [blame] | 147 | #define QERR_PROPERTY_NOT_FOUND \ |
| 148 | "{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }" |
| 149 | |
Markus Armbruster | 06b4a70 | 2010-02-19 13:17:58 +0100 | [diff] [blame] | 150 | #define QERR_PROPERTY_VALUE_BAD \ |
| 151 | "{ 'class': 'PropertyValueBad', 'data': { 'device': %s, 'property': %s, 'value': %s } }" |
| 152 | |
Markus Armbruster | 9c5eff9 | 2010-03-16 17:40:48 +0100 | [diff] [blame] | 153 | #define QERR_PROPERTY_VALUE_IN_USE \ |
| 154 | "{ 'class': 'PropertyValueInUse', 'data': { 'device': %s, 'property': %s, 'value': %s } }" |
| 155 | |
Markus Armbruster | 84745d6 | 2010-03-16 17:44:38 +0100 | [diff] [blame] | 156 | #define QERR_PROPERTY_VALUE_NOT_FOUND \ |
| 157 | "{ 'class': 'PropertyValueNotFound', 'data': { 'device': %s, 'property': %s, 'value': %s } }" |
| 158 | |
Markus Armbruster | e16a181 | 2009-12-07 21:37:02 +0100 | [diff] [blame] | 159 | #define QERR_QMP_BAD_INPUT_OBJECT \ |
| 160 | "{ 'class': 'QMPBadInputObject', 'data': { 'expected': %s } }" |
Luiz Capitulino | 4b9d468 | 2009-11-26 22:58:57 -0200 | [diff] [blame] | 161 | |
Luiz Capitulino | 7dfb612 | 2010-04-07 14:46:33 -0300 | [diff] [blame] | 162 | #define QERR_QMP_BAD_INPUT_OBJECT_MEMBER \ |
| 163 | "{ 'class': 'QMPBadInputObjectMember', 'data': { 'member': %s, 'expected': %s } }" |
| 164 | |
Luiz Capitulino | 60d76d7 | 2010-06-01 16:15:23 -0300 | [diff] [blame] | 165 | #define QERR_QMP_EXTRA_MEMBER \ |
| 166 | "{ 'class': 'QMPExtraInputObjectMember', 'data': { 'member': %s } }" |
| 167 | |
Luiz Capitulino | 6667b23 | 2011-07-29 15:57:54 -0300 | [diff] [blame] | 168 | #define QERR_RESET_REQUIRED \ |
| 169 | "{ 'class': 'ResetRequired', 'data': {} }" |
| 170 | |
Markus Armbruster | 7a84cb2 | 2009-12-07 21:37:07 +0100 | [diff] [blame] | 171 | #define QERR_SET_PASSWD_FAILED \ |
| 172 | "{ 'class': 'SetPasswdFailed', 'data': {} }" |
| 173 | |
Daniel P. Berrange | 1366108 | 2011-06-23 13:31:42 +0100 | [diff] [blame] | 174 | #define QERR_ADD_CLIENT_FAILED \ |
| 175 | "{ 'class': 'AddClientFailed', 'data': {} }" |
| 176 | |
Markus Armbruster | a488be2 | 2009-12-07 21:37:14 +0100 | [diff] [blame] | 177 | #define QERR_TOO_MANY_FILES \ |
Markus Armbruster | bd9d306 | 2009-12-08 13:33:54 +0100 | [diff] [blame] | 178 | "{ 'class': 'TooManyFiles', 'data': {} }" |
Markus Armbruster | a488be2 | 2009-12-07 21:37:14 +0100 | [diff] [blame] | 179 | |
Markus Armbruster | fc5469d | 2010-02-19 17:42:46 +0100 | [diff] [blame] | 180 | #define QERR_UNDEFINED_ERROR \ |
| 181 | "{ 'class': 'UndefinedError', 'data': {} }" |
| 182 | |
Lai Jiangshan | 4c5a1e4 | 2011-03-07 17:05:04 +0800 | [diff] [blame] | 183 | #define QERR_UNSUPPORTED \ |
| 184 | "{ 'class': 'Unsupported', 'data': {} }" |
| 185 | |
Kevin Wolf | f54e364 | 2011-02-09 11:09:38 +0100 | [diff] [blame] | 186 | #define QERR_UNKNOWN_BLOCK_FORMAT_FEATURE \ |
| 187 | "{ 'class': 'UnknownBlockFormatFeature', 'data': { 'device': %s, 'format': %s, 'feature': %s } }" |
| 188 | |
Markus Armbruster | a6906e3 | 2009-12-07 21:37:08 +0100 | [diff] [blame] | 189 | #define QERR_VNC_SERVER_FAILED \ |
| 190 | "{ 'class': 'VNCServerFailed', 'data': { 'target': %s } }" |
| 191 | |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 192 | #define QERR_FEATURE_DISABLED \ |
| 193 | "{ 'class': 'FeatureDisabled', 'data': { 'name': %s } }" |
| 194 | |
Michael Roth | e3d4d25 | 2011-07-19 15:41:55 -0500 | [diff] [blame] | 195 | #define QERR_QGA_LOGGING_FAILED \ |
| 196 | "{ 'class': 'QgaLoggingFailed', 'data': {} }" |
| 197 | |
| 198 | #define QERR_QGA_COMMAND_FAILED \ |
| 199 | "{ 'class': 'QgaCommandFailed', 'data': { 'message': %s } }" |
| 200 | |
Luiz Capitulino | 9f9daf9 | 2009-11-18 23:05:30 -0200 | [diff] [blame] | 201 | #endif /* QERROR_H */ |