2
0

qerror.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * QError Module
  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. #include "qdict.h"
  15. #include "qstring.h"
  16. #include "qemu-error.h"
  17. #include <stdarg.h>
  18. typedef struct QErrorStringTable {
  19. const char *desc;
  20. const char *error_fmt;
  21. } QErrorStringTable;
  22. typedef struct QError {
  23. QObject_HEAD;
  24. QDict *error;
  25. Location loc;
  26. int linenr;
  27. const char *file;
  28. const char *func;
  29. const QErrorStringTable *entry;
  30. } QError;
  31. QError *qerror_new(void);
  32. QError *qerror_from_info(const char *file, int linenr, const char *func,
  33. const char *fmt, va_list *va) GCC_FMT_ATTR(4, 0);
  34. QString *qerror_human(const QError *qerror);
  35. void qerror_print(QError *qerror);
  36. void qerror_report_internal(const char *file, int linenr, const char *func,
  37. const char *fmt, ...) GCC_FMT_ATTR(4, 5);
  38. QString *qerror_format(const char *fmt, QDict *error);
  39. #define qerror_report(fmt, ...) \
  40. qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
  41. QError *qobject_to_qerror(const QObject *obj);
  42. /*
  43. * QError class list
  44. * Please keep the definitions in alphabetical order.
  45. * Use "grep '^#define QERR_' qerror.h | sort -c" to check.
  46. */
  47. #define QERR_BAD_BUS_FOR_DEVICE \
  48. "{ 'class': 'BadBusForDevice', 'data': { 'device': %s, 'bad_bus_type': %s } }"
  49. #define QERR_BUS_NOT_FOUND \
  50. "{ 'class': 'BusNotFound', 'data': { 'bus': %s } }"
  51. #define QERR_BUS_NO_HOTPLUG \
  52. "{ 'class': 'BusNoHotplug', 'data': { 'bus': %s } }"
  53. #define QERR_COMMAND_NOT_FOUND \
  54. "{ 'class': 'CommandNotFound', 'data': { 'name': %s } }"
  55. #define QERR_DEVICE_ENCRYPTED \
  56. "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }"
  57. #define QERR_DEVICE_INIT_FAILED \
  58. "{ 'class': 'DeviceInitFailed', 'data': { 'device': %s } }"
  59. #define QERR_DEVICE_IN_USE \
  60. "{ 'class': 'DeviceInUse', 'data': { 'device': %s } }"
  61. #define QERR_DEVICE_LOCKED \
  62. "{ 'class': 'DeviceLocked', 'data': { 'device': %s } }"
  63. #define QERR_DEVICE_MULTIPLE_BUSSES \
  64. "{ 'class': 'DeviceMultipleBusses', 'data': { 'device': %s } }"
  65. #define QERR_DEVICE_NOT_ACTIVE \
  66. "{ 'class': 'DeviceNotActive', 'data': { 'device': %s } }"
  67. #define QERR_DEVICE_NOT_ENCRYPTED \
  68. "{ 'class': 'DeviceNotEncrypted', 'data': { 'device': %s } }"
  69. #define QERR_DEVICE_NOT_FOUND \
  70. "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
  71. #define QERR_DEVICE_NOT_REMOVABLE \
  72. "{ 'class': 'DeviceNotRemovable', 'data': { 'device': %s } }"
  73. #define QERR_DEVICE_NO_BUS \
  74. "{ 'class': 'DeviceNoBus', 'data': { 'device': %s } }"
  75. #define QERR_DEVICE_NO_HOTPLUG \
  76. "{ 'class': 'DeviceNoHotplug', 'data': { 'device': %s } }"
  77. #define QERR_DUPLICATE_ID \
  78. "{ 'class': 'DuplicateId', 'data': { 'id': %s, 'object': %s } }"
  79. #define QERR_FD_NOT_FOUND \
  80. "{ 'class': 'FdNotFound', 'data': { 'name': %s } }"
  81. #define QERR_FD_NOT_SUPPLIED \
  82. "{ 'class': 'FdNotSupplied', 'data': {} }"
  83. #define QERR_INVALID_BLOCK_FORMAT \
  84. "{ 'class': 'InvalidBlockFormat', 'data': { 'name': %s } }"
  85. #define QERR_INVALID_PARAMETER \
  86. "{ 'class': 'InvalidParameter', 'data': { 'name': %s } }"
  87. #define QERR_INVALID_PARAMETER_TYPE \
  88. "{ 'class': 'InvalidParameterType', 'data': { 'name': %s,'expected': %s } }"
  89. #define QERR_INVALID_PARAMETER_VALUE \
  90. "{ 'class': 'InvalidParameterValue', 'data': { 'name': %s, 'expected': %s } }"
  91. #define QERR_INVALID_PASSWORD \
  92. "{ 'class': 'InvalidPassword', 'data': {} }"
  93. #define QERR_JSON_PARSING \
  94. "{ 'class': 'JSONParsing', 'data': {} }"
  95. #define QERR_JSON_PARSE_ERROR \
  96. "{ 'class': 'JSONParseError', 'data': { 'message': %s } }"
  97. #define QERR_BUFFER_OVERRUN \
  98. "{ 'class': 'BufferOverrun', 'data': {} }"
  99. #define QERR_KVM_MISSING_CAP \
  100. "{ 'class': 'KVMMissingCap', 'data': { 'capability': %s, 'feature': %s } }"
  101. #define QERR_MIGRATION_EXPECTED \
  102. "{ 'class': 'MigrationExpected', 'data': {} }"
  103. #define QERR_MISSING_PARAMETER \
  104. "{ 'class': 'MissingParameter', 'data': { 'name': %s } }"
  105. #define QERR_NO_BUS_FOR_DEVICE \
  106. "{ 'class': 'NoBusForDevice', 'data': { 'device': %s, 'bus': %s } }"
  107. #define QERR_OPEN_FILE_FAILED \
  108. "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
  109. #define QERR_PROPERTY_NOT_FOUND \
  110. "{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }"
  111. #define QERR_PROPERTY_VALUE_BAD \
  112. "{ 'class': 'PropertyValueBad', 'data': { 'device': %s, 'property': %s, 'value': %s } }"
  113. #define QERR_PROPERTY_VALUE_IN_USE \
  114. "{ 'class': 'PropertyValueInUse', 'data': { 'device': %s, 'property': %s, 'value': %s } }"
  115. #define QERR_PROPERTY_VALUE_NOT_FOUND \
  116. "{ 'class': 'PropertyValueNotFound', 'data': { 'device': %s, 'property': %s, 'value': %s } }"
  117. #define QERR_QMP_BAD_INPUT_OBJECT \
  118. "{ 'class': 'QMPBadInputObject', 'data': { 'expected': %s } }"
  119. #define QERR_QMP_BAD_INPUT_OBJECT_MEMBER \
  120. "{ 'class': 'QMPBadInputObjectMember', 'data': { 'member': %s, 'expected': %s } }"
  121. #define QERR_QMP_EXTRA_MEMBER \
  122. "{ 'class': 'QMPExtraInputObjectMember', 'data': { 'member': %s } }"
  123. #define QERR_SET_PASSWD_FAILED \
  124. "{ 'class': 'SetPasswdFailed', 'data': {} }"
  125. #define QERR_ADD_CLIENT_FAILED \
  126. "{ 'class': 'AddClientFailed', 'data': {} }"
  127. #define QERR_TOO_MANY_FILES \
  128. "{ 'class': 'TooManyFiles', 'data': {} }"
  129. #define QERR_UNDEFINED_ERROR \
  130. "{ 'class': 'UndefinedError', 'data': {} }"
  131. #define QERR_UNSUPPORTED \
  132. "{ 'class': 'Unsupported', 'data': {} }"
  133. #define QERR_UNKNOWN_BLOCK_FORMAT_FEATURE \
  134. "{ 'class': 'UnknownBlockFormatFeature', 'data': { 'device': %s, 'format': %s, 'feature': %s } }"
  135. #define QERR_VNC_SERVER_FAILED \
  136. "{ 'class': 'VNCServerFailed', 'data': { 'target': %s } }"
  137. #define QERR_FEATURE_DISABLED \
  138. "{ 'class': 'FeatureDisabled', 'data': { 'name': %s } }"
  139. #define QERR_QGA_LOGGING_FAILED \
  140. "{ 'class': 'QgaLoggingFailed', 'data': {} }"
  141. #define QERR_QGA_COMMAND_FAILED \
  142. "{ 'class': 'QgaCommandFailed', 'data': { 'message': %s } }"
  143. #endif /* QERROR_H */