error: New error_prepend(), error_reportf_err()

Instead of simply propagating an error verbatim, we sometimes want to
add to its message, like this:

    frobnicate(arg, &err);
    error_setg(errp, "Can't frobnicate %s: %s",
                     arg, error_get_pretty(err));
    error_free(err);

This is suboptimal, because it loses err's hint (if any).  Moreover,
when errp is &error_abort or is subsequently propagated to
&error_abort, the abort message points to the place where we last
added to the error, not to the place where it originated.

To avoid these issues, provide means to add to an error's message in
place:

    frobnicate(arg, errp);
    error_prepend(errp, "Can't frobnicate %s: ", arg);

Likewise, reporting an error like

    frobnicate(arg, &err);
    error_report("Can't frobnicate %s: %s", arg, error_get_pretty(err));

can lose err's hint.  To avoid:

    error_reportf_err(err, "Can't frobnicate %s: ", arg);

The next commits will put these functions to use.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <1450452927-8346-10-git-send-email-armbru@redhat.com>
2 files changed
tree: fbbde8c5f68714997853f8660136d8c2efec740d
  1. audio/
  2. backends/
  3. block/
  4. bsd-user/
  5. contrib/
  6. crypto/
  7. default-configs/
  8. disas/
  9. docs/
  10. fpu/
  11. fsdev/
  12. gdb-xml/
  13. hw/
  14. include/
  15. io/
  16. libdecnumber/
  17. linux-headers/
  18. linux-user/
  19. migration/
  20. net/
  21. pc-bios/
  22. po/
  23. qapi/
  24. qga/
  25. qobject/
  26. qom/
  27. replay/
  28. roms/
  29. scripts/
  30. slirp/
  31. stubs/
  32. target-alpha/
  33. target-arm/
  34. target-cris/
  35. target-i386/
  36. target-lm32/
  37. target-m68k/
  38. target-microblaze/
  39. target-mips/
  40. target-moxie/
  41. target-openrisc/
  42. target-ppc/
  43. target-s390x/
  44. target-sh4/
  45. target-sparc/
  46. target-tilegx/
  47. target-tricore/
  48. target-unicore32/
  49. target-xtensa/
  50. tcg/
  51. tests/
  52. trace/
  53. ui/
  54. util/
  55. .dir-locals.el
  56. .exrc
  57. .gitignore
  58. .gitmodules
  59. .mailmap
  60. .travis.yml
  61. accel.c
  62. aio-posix.c
  63. aio-win32.c
  64. arch_init.c
  65. async.c
  66. balloon.c
  67. block.c
  68. blockdev-nbd.c
  69. blockdev.c
  70. blockjob.c
  71. bootdevice.c
  72. bt-host.c
  73. bt-vhci.c
  74. Changelog
  75. CODING_STYLE
  76. configure
  77. COPYING
  78. COPYING.LIB
  79. cpu-exec-common.c
  80. cpu-exec.c
  81. cpus.c
  82. cputlb.c
  83. device-hotplug.c
  84. device_tree.c
  85. disas.c
  86. dma-helpers.c
  87. dump.c
  88. exec.c
  89. gdbstub.c
  90. HACKING
  91. hmp-commands-info.hx
  92. hmp-commands.hx
  93. hmp.c
  94. hmp.h
  95. iohandler.c
  96. ioport.c
  97. iothread.c
  98. kvm-all.c
  99. kvm-stub.c
  100. LICENSE
  101. main-loop.c
  102. MAINTAINERS
  103. Makefile
  104. Makefile.objs
  105. Makefile.target
  106. memory.c
  107. memory_mapping.c
  108. module-common.c
  109. monitor.c
  110. nbd.c
  111. numa.c
  112. os-posix.c
  113. os-win32.c
  114. page_cache.c
  115. qapi-schema.json
  116. qdev-monitor.c
  117. qdict-test-data.txt
  118. qemu-bridge-helper.c
  119. qemu-char.c
  120. qemu-doc.texi
  121. qemu-ga.texi
  122. qemu-img-cmds.hx
  123. qemu-img.c
  124. qemu-img.texi
  125. qemu-io-cmds.c
  126. qemu-io.c
  127. qemu-log.c
  128. qemu-nbd.c
  129. qemu-nbd.texi
  130. qemu-options-wrapper.h
  131. qemu-options.h
  132. qemu-options.hx
  133. qemu-seccomp.c
  134. qemu-tech.texi
  135. qemu-timer.c
  136. qemu.nsi
  137. qemu.sasl
  138. qjson.c
  139. qmp-commands.hx
  140. qmp.c
  141. qtest.c
  142. README
  143. rules.mak
  144. softmmu_template.h
  145. spice-qemu-char.c
  146. tcg-runtime.c
  147. tci.c
  148. thread-pool.c
  149. thunk.c
  150. tpm.c
  151. trace-events
  152. translate-all.c
  153. translate-all.h
  154. translate-common.c
  155. user-exec.c
  156. VERSION
  157. version.rc
  158. vl.c
  159. xen-common-stub.c
  160. xen-common.c
  161. xen-hvm-stub.c
  162. xen-hvm.c
  163. xen-mapcache.c