2011-06-01 21:14:49 +04:00
|
|
|
/*
|
|
|
|
* QEMU Error Objects
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2011
|
2015-09-11 17:51:42 +03:00
|
|
|
* Copyright (C) 2011-2015 Red Hat, Inc.
|
2011-06-01 21:14:49 +04:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
2015-09-11 17:51:42 +03:00
|
|
|
* Markus Armbruster <armbru@redhat.com>,
|
2011-06-01 21:14:49 +04:00
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU LGPL, version 2. See
|
|
|
|
* the COPYING.LIB file in the top-level directory.
|
|
|
|
*/
|
2011-06-14 01:01:53 +04:00
|
|
|
|
2016-01-29 20:49:55 +03:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2014-03-22 03:42:28 +04:00
|
|
|
#include "qemu/error-report.h"
|
2011-06-01 21:14:49 +04:00
|
|
|
|
|
|
|
struct Error
|
|
|
|
{
|
|
|
|
char *msg;
|
2012-07-27 21:09:29 +04:00
|
|
|
ErrorClass err_class;
|
error: On abort, report where the error was created
This is particularly useful when we abort in error_propagate(),
because there the stack backtrace doesn't lead to where the error was
created. Looks like this:
Unexpected error in parse_block_error_action() at .../qemu/blockdev.c:322:
qemu-system-x86_64: -drive if=none,werror=foo: 'foo' invalid write error action
Aborted (core dumped)
Note: to get this example output, I monkey-patched drive_new() to pass
&error_abort to blockdev_init().
To keep the error handling boiler plate from growing even more, all
error_setFOO() become macros expanding into error_setFOO_internal()
with additional __FILE__, __LINE__, __func__ arguments. Not exactly
pretty, but it works.
The macro trickery breaks down when you take the address of an
error_setFOO(). Fortunately, we do that in just one place: qemu-ga's
Windows VSS provider and requester DLL wants to call
error_setg_win32() through a function pointer "to avoid linking glib
to the DLL". Use error_setg_win32_internal() there. The use of the
function pointer is already wrapped in a macro, so the churn isn't
bad.
Code size increases by some 35KiB for me (0.7%). Tolerable. Could be
less if we passed relative rather than absolute source file names to
the compiler, or forwent reporting __func__.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2015-06-19 20:21:59 +03:00
|
|
|
const char *src, *func;
|
|
|
|
int line;
|
hmp: Allow for error message hints on HMP
Commits 7216ae3d and d2828429 disabled some error message hints,
all because a change to use modern error reporting meant that the
hint would be output prior to the actual error. Fix this by making
hints a first-class member of Error.
For example, we are now back to the pleasant:
$ qemu-system-x86_64 --nodefaults -S --vnc :0 --chardev null,id=,
qemu-system-x86_64: --chardev null,id=,: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1441901956-21991-1-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-09-10 19:19:16 +03:00
|
|
|
GString *hint;
|
2011-06-01 21:14:49 +04:00
|
|
|
};
|
|
|
|
|
2014-01-02 06:46:59 +04:00
|
|
|
Error *error_abort;
|
2015-09-11 17:51:42 +03:00
|
|
|
Error *error_fatal;
|
2014-01-02 06:46:59 +04:00
|
|
|
|
2015-09-11 17:51:42 +03:00
|
|
|
static void error_handle_fatal(Error **errp, Error *err)
|
error: On abort, report where the error was created
This is particularly useful when we abort in error_propagate(),
because there the stack backtrace doesn't lead to where the error was
created. Looks like this:
Unexpected error in parse_block_error_action() at .../qemu/blockdev.c:322:
qemu-system-x86_64: -drive if=none,werror=foo: 'foo' invalid write error action
Aborted (core dumped)
Note: to get this example output, I monkey-patched drive_new() to pass
&error_abort to blockdev_init().
To keep the error handling boiler plate from growing even more, all
error_setFOO() become macros expanding into error_setFOO_internal()
with additional __FILE__, __LINE__, __func__ arguments. Not exactly
pretty, but it works.
The macro trickery breaks down when you take the address of an
error_setFOO(). Fortunately, we do that in just one place: qemu-ga's
Windows VSS provider and requester DLL wants to call
error_setg_win32() through a function pointer "to avoid linking glib
to the DLL". Use error_setg_win32_internal() there. The use of the
function pointer is already wrapped in a macro, so the churn isn't
bad.
Code size increases by some 35KiB for me (0.7%). Tolerable. Could be
less if we passed relative rather than absolute source file names to
the compiler, or forwent reporting __func__.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2015-06-19 20:21:59 +03:00
|
|
|
{
|
2015-09-11 17:51:42 +03:00
|
|
|
if (errp == &error_abort) {
|
|
|
|
fprintf(stderr, "Unexpected error in %s() at %s:%d:\n",
|
|
|
|
err->func, err->src, err->line);
|
2019-04-15 17:25:19 +03:00
|
|
|
error_report("%s", error_get_pretty(err));
|
|
|
|
if (err->hint) {
|
|
|
|
error_printf("%s", err->hint->str);
|
|
|
|
}
|
2015-09-11 17:51:42 +03:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (errp == &error_fatal) {
|
|
|
|
error_report_err(err);
|
|
|
|
exit(1);
|
|
|
|
}
|
error: On abort, report where the error was created
This is particularly useful when we abort in error_propagate(),
because there the stack backtrace doesn't lead to where the error was
created. Looks like this:
Unexpected error in parse_block_error_action() at .../qemu/blockdev.c:322:
qemu-system-x86_64: -drive if=none,werror=foo: 'foo' invalid write error action
Aborted (core dumped)
Note: to get this example output, I monkey-patched drive_new() to pass
&error_abort to blockdev_init().
To keep the error handling boiler plate from growing even more, all
error_setFOO() become macros expanding into error_setFOO_internal()
with additional __FILE__, __LINE__, __func__ arguments. Not exactly
pretty, but it works.
The macro trickery breaks down when you take the address of an
error_setFOO(). Fortunately, we do that in just one place: qemu-ga's
Windows VSS provider and requester DLL wants to call
error_setg_win32() through a function pointer "to avoid linking glib
to the DLL". Use error_setg_win32_internal() there. The use of the
function pointer is already wrapped in a macro, so the churn isn't
bad.
Code size increases by some 35KiB for me (0.7%). Tolerable. Could be
less if we passed relative rather than absolute source file names to
the compiler, or forwent reporting __func__.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2015-06-19 20:21:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void error_setv(Error **errp,
|
|
|
|
const char *src, int line, const char *func,
|
2016-03-09 20:28:24 +03:00
|
|
|
ErrorClass err_class, const char *fmt, va_list ap,
|
|
|
|
const char *suffix)
|
2011-06-01 21:14:49 +04:00
|
|
|
{
|
|
|
|
Error *err;
|
2013-11-07 23:10:29 +04:00
|
|
|
int saved_errno = errno;
|
2011-06-01 21:14:49 +04:00
|
|
|
|
|
|
|
if (errp == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-17 18:17:04 +04:00
|
|
|
assert(*errp == NULL);
|
2011-06-01 21:14:49 +04:00
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
err = g_malloc0(sizeof(*err));
|
2012-07-28 00:51:03 +04:00
|
|
|
err->msg = g_strdup_vprintf(fmt, ap);
|
2016-03-09 20:28:24 +03:00
|
|
|
if (suffix) {
|
|
|
|
char *msg = err->msg;
|
|
|
|
err->msg = g_strdup_printf("%s: %s", msg, suffix);
|
|
|
|
g_free(msg);
|
|
|
|
}
|
2012-07-27 21:09:29 +04:00
|
|
|
err->err_class = err_class;
|
error: On abort, report where the error was created
This is particularly useful when we abort in error_propagate(),
because there the stack backtrace doesn't lead to where the error was
created. Looks like this:
Unexpected error in parse_block_error_action() at .../qemu/blockdev.c:322:
qemu-system-x86_64: -drive if=none,werror=foo: 'foo' invalid write error action
Aborted (core dumped)
Note: to get this example output, I monkey-patched drive_new() to pass
&error_abort to blockdev_init().
To keep the error handling boiler plate from growing even more, all
error_setFOO() become macros expanding into error_setFOO_internal()
with additional __FILE__, __LINE__, __func__ arguments. Not exactly
pretty, but it works.
The macro trickery breaks down when you take the address of an
error_setFOO(). Fortunately, we do that in just one place: qemu-ga's
Windows VSS provider and requester DLL wants to call
error_setg_win32() through a function pointer "to avoid linking glib
to the DLL". Use error_setg_win32_internal() there. The use of the
function pointer is already wrapped in a macro, so the churn isn't
bad.
Code size increases by some 35KiB for me (0.7%). Tolerable. Could be
less if we passed relative rather than absolute source file names to
the compiler, or forwent reporting __func__.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2015-06-19 20:21:59 +03:00
|
|
|
err->src = src;
|
|
|
|
err->line = line;
|
|
|
|
err->func = func;
|
2011-06-01 21:14:49 +04:00
|
|
|
|
2015-09-11 17:51:42 +03:00
|
|
|
error_handle_fatal(errp, err);
|
2011-06-01 21:14:49 +04:00
|
|
|
*errp = err;
|
2013-11-07 23:10:29 +04:00
|
|
|
|
|
|
|
errno = saved_errno;
|
2011-06-01 21:14:49 +04:00
|
|
|
}
|
|
|
|
|
error: On abort, report where the error was created
This is particularly useful when we abort in error_propagate(),
because there the stack backtrace doesn't lead to where the error was
created. Looks like this:
Unexpected error in parse_block_error_action() at .../qemu/blockdev.c:322:
qemu-system-x86_64: -drive if=none,werror=foo: 'foo' invalid write error action
Aborted (core dumped)
Note: to get this example output, I monkey-patched drive_new() to pass
&error_abort to blockdev_init().
To keep the error handling boiler plate from growing even more, all
error_setFOO() become macros expanding into error_setFOO_internal()
with additional __FILE__, __LINE__, __func__ arguments. Not exactly
pretty, but it works.
The macro trickery breaks down when you take the address of an
error_setFOO(). Fortunately, we do that in just one place: qemu-ga's
Windows VSS provider and requester DLL wants to call
error_setg_win32() through a function pointer "to avoid linking glib
to the DLL". Use error_setg_win32_internal() there. The use of the
function pointer is already wrapped in a macro, so the churn isn't
bad.
Code size increases by some 35KiB for me (0.7%). Tolerable. Could be
less if we passed relative rather than absolute source file names to
the compiler, or forwent reporting __func__.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2015-06-19 20:21:59 +03:00
|
|
|
void error_set_internal(Error **errp,
|
|
|
|
const char *src, int line, const char *func,
|
|
|
|
ErrorClass err_class, const char *fmt, ...)
|
2015-06-19 14:59:47 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2016-03-09 20:28:24 +03:00
|
|
|
error_setv(errp, src, line, func, err_class, fmt, ap, NULL);
|
2015-06-19 14:59:47 +03:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
error: On abort, report where the error was created
This is particularly useful when we abort in error_propagate(),
because there the stack backtrace doesn't lead to where the error was
created. Looks like this:
Unexpected error in parse_block_error_action() at .../qemu/blockdev.c:322:
qemu-system-x86_64: -drive if=none,werror=foo: 'foo' invalid write error action
Aborted (core dumped)
Note: to get this example output, I monkey-patched drive_new() to pass
&error_abort to blockdev_init().
To keep the error handling boiler plate from growing even more, all
error_setFOO() become macros expanding into error_setFOO_internal()
with additional __FILE__, __LINE__, __func__ arguments. Not exactly
pretty, but it works.
The macro trickery breaks down when you take the address of an
error_setFOO(). Fortunately, we do that in just one place: qemu-ga's
Windows VSS provider and requester DLL wants to call
error_setg_win32() through a function pointer "to avoid linking glib
to the DLL". Use error_setg_win32_internal() there. The use of the
function pointer is already wrapped in a macro, so the churn isn't
bad.
Code size increases by some 35KiB for me (0.7%). Tolerable. Could be
less if we passed relative rather than absolute source file names to
the compiler, or forwent reporting __func__.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2015-06-19 20:21:59 +03:00
|
|
|
void error_setg_internal(Error **errp,
|
|
|
|
const char *src, int line, const char *func,
|
|
|
|
const char *fmt, ...)
|
2015-06-19 16:36:16 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2016-03-09 20:28:24 +03:00
|
|
|
error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap, NULL);
|
2015-06-19 16:36:16 +03:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
error: On abort, report where the error was created
This is particularly useful when we abort in error_propagate(),
because there the stack backtrace doesn't lead to where the error was
created. Looks like this:
Unexpected error in parse_block_error_action() at .../qemu/blockdev.c:322:
qemu-system-x86_64: -drive if=none,werror=foo: 'foo' invalid write error action
Aborted (core dumped)
Note: to get this example output, I monkey-patched drive_new() to pass
&error_abort to blockdev_init().
To keep the error handling boiler plate from growing even more, all
error_setFOO() become macros expanding into error_setFOO_internal()
with additional __FILE__, __LINE__, __func__ arguments. Not exactly
pretty, but it works.
The macro trickery breaks down when you take the address of an
error_setFOO(). Fortunately, we do that in just one place: qemu-ga's
Windows VSS provider and requester DLL wants to call
error_setg_win32() through a function pointer "to avoid linking glib
to the DLL". Use error_setg_win32_internal() there. The use of the
function pointer is already wrapped in a macro, so the churn isn't
bad.
Code size increases by some 35KiB for me (0.7%). Tolerable. Could be
less if we passed relative rather than absolute source file names to
the compiler, or forwent reporting __func__.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2015-06-19 20:21:59 +03:00
|
|
|
void error_setg_errno_internal(Error **errp,
|
|
|
|
const char *src, int line, const char *func,
|
|
|
|
int os_errno, const char *fmt, ...)
|
2012-10-02 11:00:45 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
2013-11-07 23:10:29 +04:00
|
|
|
int saved_errno = errno;
|
2012-10-02 11:00:45 +04:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2016-03-09 20:28:24 +03:00
|
|
|
error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap,
|
|
|
|
os_errno != 0 ? strerror(os_errno) : NULL);
|
2012-10-02 11:00:45 +04:00
|
|
|
va_end(ap);
|
|
|
|
|
2013-11-07 23:10:29 +04:00
|
|
|
errno = saved_errno;
|
2012-10-02 11:00:45 +04:00
|
|
|
}
|
|
|
|
|
error: On abort, report where the error was created
This is particularly useful when we abort in error_propagate(),
because there the stack backtrace doesn't lead to where the error was
created. Looks like this:
Unexpected error in parse_block_error_action() at .../qemu/blockdev.c:322:
qemu-system-x86_64: -drive if=none,werror=foo: 'foo' invalid write error action
Aborted (core dumped)
Note: to get this example output, I monkey-patched drive_new() to pass
&error_abort to blockdev_init().
To keep the error handling boiler plate from growing even more, all
error_setFOO() become macros expanding into error_setFOO_internal()
with additional __FILE__, __LINE__, __func__ arguments. Not exactly
pretty, but it works.
The macro trickery breaks down when you take the address of an
error_setFOO(). Fortunately, we do that in just one place: qemu-ga's
Windows VSS provider and requester DLL wants to call
error_setg_win32() through a function pointer "to avoid linking glib
to the DLL". Use error_setg_win32_internal() there. The use of the
function pointer is already wrapped in a macro, so the churn isn't
bad.
Code size increases by some 35KiB for me (0.7%). Tolerable. Could be
less if we passed relative rather than absolute source file names to
the compiler, or forwent reporting __func__.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2015-06-19 20:21:59 +03:00
|
|
|
void error_setg_file_open_internal(Error **errp,
|
|
|
|
const char *src, int line, const char *func,
|
|
|
|
int os_errno, const char *filename)
|
2013-06-07 22:24:49 +04:00
|
|
|
{
|
error: On abort, report where the error was created
This is particularly useful when we abort in error_propagate(),
because there the stack backtrace doesn't lead to where the error was
created. Looks like this:
Unexpected error in parse_block_error_action() at .../qemu/blockdev.c:322:
qemu-system-x86_64: -drive if=none,werror=foo: 'foo' invalid write error action
Aborted (core dumped)
Note: to get this example output, I monkey-patched drive_new() to pass
&error_abort to blockdev_init().
To keep the error handling boiler plate from growing even more, all
error_setFOO() become macros expanding into error_setFOO_internal()
with additional __FILE__, __LINE__, __func__ arguments. Not exactly
pretty, but it works.
The macro trickery breaks down when you take the address of an
error_setFOO(). Fortunately, we do that in just one place: qemu-ga's
Windows VSS provider and requester DLL wants to call
error_setg_win32() through a function pointer "to avoid linking glib
to the DLL". Use error_setg_win32_internal() there. The use of the
function pointer is already wrapped in a macro, so the churn isn't
bad.
Code size increases by some 35KiB for me (0.7%). Tolerable. Could be
less if we passed relative rather than absolute source file names to
the compiler, or forwent reporting __func__.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2015-06-19 20:21:59 +03:00
|
|
|
error_setg_errno_internal(errp, src, line, func, os_errno,
|
|
|
|
"Could not open '%s'", filename);
|
2013-06-07 22:24:49 +04:00
|
|
|
}
|
|
|
|
|
2019-12-05 20:46:17 +03:00
|
|
|
void error_vprepend(Error *const *errp, const char *fmt, va_list ap)
|
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>
2015-12-18 18:35:12 +03:00
|
|
|
{
|
|
|
|
GString *newmsg;
|
|
|
|
|
|
|
|
if (!errp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
newmsg = g_string_new(NULL);
|
|
|
|
g_string_vprintf(newmsg, fmt, ap);
|
|
|
|
g_string_append(newmsg, (*errp)->msg);
|
2017-04-13 19:09:52 +03:00
|
|
|
g_free((*errp)->msg);
|
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>
2015-12-18 18:35:12 +03:00
|
|
|
(*errp)->msg = g_string_free(newmsg, 0);
|
|
|
|
}
|
|
|
|
|
2019-12-05 20:46:17 +03:00
|
|
|
void error_prepend(Error *const *errp, const char *fmt, ...)
|
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>
2015-12-18 18:35:12 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
error_vprepend(errp, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2019-12-05 20:46:17 +03:00
|
|
|
void error_append_hint(Error *const *errp, const char *fmt, ...)
|
hmp: Allow for error message hints on HMP
Commits 7216ae3d and d2828429 disabled some error message hints,
all because a change to use modern error reporting meant that the
hint would be output prior to the actual error. Fix this by making
hints a first-class member of Error.
For example, we are now back to the pleasant:
$ qemu-system-x86_64 --nodefaults -S --vnc :0 --chardev null,id=,
qemu-system-x86_64: --chardev null,id=,: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1441901956-21991-1-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-09-10 19:19:16 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int saved_errno = errno;
|
|
|
|
Error *err;
|
|
|
|
|
|
|
|
if (!errp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
err = *errp;
|
2015-12-18 18:35:08 +03:00
|
|
|
assert(err && errp != &error_abort && errp != &error_fatal);
|
hmp: Allow for error message hints on HMP
Commits 7216ae3d and d2828429 disabled some error message hints,
all because a change to use modern error reporting meant that the
hint would be output prior to the actual error. Fix this by making
hints a first-class member of Error.
For example, we are now back to the pleasant:
$ qemu-system-x86_64 --nodefaults -S --vnc :0 --chardev null,id=,
qemu-system-x86_64: --chardev null,id=,: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1441901956-21991-1-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-09-10 19:19:16 +03:00
|
|
|
|
|
|
|
if (!err->hint) {
|
|
|
|
err->hint = g_string_new(NULL);
|
|
|
|
}
|
|
|
|
va_start(ap, fmt);
|
|
|
|
g_string_append_vprintf(err->hint, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
errno = saved_errno;
|
|
|
|
}
|
|
|
|
|
2013-08-07 19:40:11 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
error: On abort, report where the error was created
This is particularly useful when we abort in error_propagate(),
because there the stack backtrace doesn't lead to where the error was
created. Looks like this:
Unexpected error in parse_block_error_action() at .../qemu/blockdev.c:322:
qemu-system-x86_64: -drive if=none,werror=foo: 'foo' invalid write error action
Aborted (core dumped)
Note: to get this example output, I monkey-patched drive_new() to pass
&error_abort to blockdev_init().
To keep the error handling boiler plate from growing even more, all
error_setFOO() become macros expanding into error_setFOO_internal()
with additional __FILE__, __LINE__, __func__ arguments. Not exactly
pretty, but it works.
The macro trickery breaks down when you take the address of an
error_setFOO(). Fortunately, we do that in just one place: qemu-ga's
Windows VSS provider and requester DLL wants to call
error_setg_win32() through a function pointer "to avoid linking glib
to the DLL". Use error_setg_win32_internal() there. The use of the
function pointer is already wrapped in a macro, so the churn isn't
bad.
Code size increases by some 35KiB for me (0.7%). Tolerable. Could be
less if we passed relative rather than absolute source file names to
the compiler, or forwent reporting __func__.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
2015-06-19 20:21:59 +03:00
|
|
|
void error_setg_win32_internal(Error **errp,
|
|
|
|
const char *src, int line, const char *func,
|
|
|
|
int win32_err, const char *fmt, ...)
|
2013-08-07 19:40:11 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
2016-03-09 20:28:24 +03:00
|
|
|
char *suffix = NULL;
|
2013-08-07 19:40:11 +04:00
|
|
|
|
|
|
|
if (errp == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-09 20:28:24 +03:00
|
|
|
if (win32_err != 0) {
|
|
|
|
suffix = g_win32_error_message(win32_err);
|
|
|
|
}
|
|
|
|
|
2013-08-07 19:40:11 +04:00
|
|
|
va_start(ap, fmt);
|
2016-03-09 20:28:24 +03:00
|
|
|
error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR,
|
|
|
|
fmt, ap, suffix);
|
2015-06-19 14:59:47 +03:00
|
|
|
va_end(ap);
|
|
|
|
|
2016-03-09 20:28:24 +03:00
|
|
|
g_free(suffix);
|
2013-08-07 19:40:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-12-05 22:04:05 +04:00
|
|
|
Error *error_copy(const Error *err)
|
|
|
|
{
|
|
|
|
Error *err_new;
|
|
|
|
|
|
|
|
err_new = g_malloc0(sizeof(*err));
|
|
|
|
err_new->msg = g_strdup(err->msg);
|
2012-07-27 21:09:29 +04:00
|
|
|
err_new->err_class = err->err_class;
|
2015-09-10 19:34:50 +03:00
|
|
|
err_new->src = err->src;
|
|
|
|
err_new->line = err->line;
|
|
|
|
err_new->func = err->func;
|
hmp: Allow for error message hints on HMP
Commits 7216ae3d and d2828429 disabled some error message hints,
all because a change to use modern error reporting meant that the
hint would be output prior to the actual error. Fix this by making
hints a first-class member of Error.
For example, we are now back to the pleasant:
$ qemu-system-x86_64 --nodefaults -S --vnc :0 --chardev null,id=,
qemu-system-x86_64: --chardev null,id=,: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1441901956-21991-1-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-09-10 19:19:16 +03:00
|
|
|
if (err->hint) {
|
|
|
|
err_new->hint = g_string_new(err->hint->str);
|
|
|
|
}
|
2011-12-05 22:04:05 +04:00
|
|
|
|
|
|
|
return err_new;
|
|
|
|
}
|
|
|
|
|
2012-08-01 23:29:38 +04:00
|
|
|
ErrorClass error_get_class(const Error *err)
|
|
|
|
{
|
|
|
|
return err->err_class;
|
|
|
|
}
|
|
|
|
|
migration: add reporting of errors for outgoing migration
Currently if an application initiates an outgoing migration,
it may or may not, get an error reported back on failure. If
the error occurs synchronously to the 'migrate' command
execution, the client app will see the error message. This
is the case for DNS lookup failures. If the error occurs
asynchronously to the monitor command though, the error
will be thrown away and the client left guessing about
what went wrong. This is the case for failure to connect
to the TCP server (eg due to wrong port, or firewall
rules, or other similar errors).
In the future we'll be adding more scope for errors to
happen asynchronously with the TLS protocol handshake.
TLS errors are hard to diagnose even when they are well
reported, so discarding errors entirely will make it
impossible to debug TLS connection problems.
Management apps which do migration are already using
'query-migrate' / 'info migrate' to check up on progress
of background migration operations and to see their end
status. This is a fine place to also include the error
message when things go wrong.
This patch thus adds an 'error-desc' field to the
MigrationInfo struct, which will be populated when
the 'status' is set to 'failed':
(qemu) migrate -d tcp:localhost:9001
(qemu) info migrate
capabilities: xbzrle: off rdma-pin-all: off auto-converge: off zero-blocks: off compress: off events: off x-postcopy-ram: off
Migration status: failed (Error connecting to socket: Connection refused)
total time: 0 milliseconds
In the HMP, when doing non-detached migration, it is
also possible to display this error message directly
to the app.
(qemu) migrate tcp:localhost:9001
Error connecting to socket: Connection refused
Or with QMP
{
"execute": "query-migrate",
"arguments": {}
}
{
"return": {
"status": "failed",
"error-desc": "address resolution failed for myhost:9000: No address associated with hostname"
}
}
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Message-Id: <1461751518-12128-11-git-send-email-berrange@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
2016-04-27 13:05:00 +03:00
|
|
|
const char *error_get_pretty(const Error *err)
|
2011-06-01 21:14:49 +04:00
|
|
|
{
|
|
|
|
return err->msg;
|
|
|
|
}
|
|
|
|
|
2015-02-06 17:27:19 +03:00
|
|
|
void error_report_err(Error *err)
|
|
|
|
{
|
|
|
|
error_report("%s", error_get_pretty(err));
|
hmp: Allow for error message hints on HMP
Commits 7216ae3d and d2828429 disabled some error message hints,
all because a change to use modern error reporting meant that the
hint would be output prior to the actual error. Fix this by making
hints a first-class member of Error.
For example, we are now back to the pleasant:
$ qemu-system-x86_64 --nodefaults -S --vnc :0 --chardev null,id=,
qemu-system-x86_64: --chardev null,id=,: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1441901956-21991-1-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-09-10 19:19:16 +03:00
|
|
|
if (err->hint) {
|
error: Fix error_report_err(), warn_report_err() hint printing
Before the from qerror_report() to error_setg(), hints looked like
this:
qerror_report(QERR_MACRO, ... arguments ...);
error_printf_unless_qmp(... hint ...);
error_printf_unless_qmp() made perfect sense: it printed exactly when
qerror_report() did.
After the conversion to error_setg():
error_setg(errp, QERR_MACRO, ... arguments ...);
error_printf_unless_qmp(... hint ...);
The "unless QMP part" still made some sense; in QMP context, the
caller generally uses the error as QMP response instead of printing
it.
However, everything else is wrong. If the caller handles the error,
the hint gets printed anyway (unless QMP). If the caller reports the
error, the hint gets printed *before* the report (unless QMP) or not
at all (if QMP).
Commit 50b7b000c91 fixed this by making hints a member of Error. It
kept printing hints with error_printf_unless_qmp():
void error_report_err(Error *err)
{
error_report("%s", error_get_pretty(err));
+ if (err->hint) {
+ error_printf_unless_qmp("%s\n", err->hint->str);
+ }
error_free(err);
}
This is wrong. We should (and now can) print the hint exactly when we
print the error.
The mistake has since been copied to warn_report_err() in commit
e43ead1d0b9.
Fix both to use error_printf().
Reported-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Cc: Eric Blake <eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190416153850.5186-1-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
[Commit message tweaked]
2019-04-16 18:38:50 +03:00
|
|
|
error_printf("%s", err->hint->str);
|
hmp: Allow for error message hints on HMP
Commits 7216ae3d and d2828429 disabled some error message hints,
all because a change to use modern error reporting meant that the
hint would be output prior to the actual error. Fix this by making
hints a first-class member of Error.
For example, we are now back to the pleasant:
$ qemu-system-x86_64 --nodefaults -S --vnc :0 --chardev null,id=,
qemu-system-x86_64: --chardev null,id=,: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1441901956-21991-1-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-09-10 19:19:16 +03:00
|
|
|
}
|
2015-02-06 17:27:19 +03:00
|
|
|
error_free(err);
|
|
|
|
}
|
|
|
|
|
2017-07-12 16:57:52 +03:00
|
|
|
void warn_report_err(Error *err)
|
|
|
|
{
|
|
|
|
warn_report("%s", error_get_pretty(err));
|
|
|
|
if (err->hint) {
|
error: Fix error_report_err(), warn_report_err() hint printing
Before the from qerror_report() to error_setg(), hints looked like
this:
qerror_report(QERR_MACRO, ... arguments ...);
error_printf_unless_qmp(... hint ...);
error_printf_unless_qmp() made perfect sense: it printed exactly when
qerror_report() did.
After the conversion to error_setg():
error_setg(errp, QERR_MACRO, ... arguments ...);
error_printf_unless_qmp(... hint ...);
The "unless QMP part" still made some sense; in QMP context, the
caller generally uses the error as QMP response instead of printing
it.
However, everything else is wrong. If the caller handles the error,
the hint gets printed anyway (unless QMP). If the caller reports the
error, the hint gets printed *before* the report (unless QMP) or not
at all (if QMP).
Commit 50b7b000c91 fixed this by making hints a member of Error. It
kept printing hints with error_printf_unless_qmp():
void error_report_err(Error *err)
{
error_report("%s", error_get_pretty(err));
+ if (err->hint) {
+ error_printf_unless_qmp("%s\n", err->hint->str);
+ }
error_free(err);
}
This is wrong. We should (and now can) print the hint exactly when we
print the error.
The mistake has since been copied to warn_report_err() in commit
e43ead1d0b9.
Fix both to use error_printf().
Reported-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Cc: Eric Blake <eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190416153850.5186-1-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
[Commit message tweaked]
2019-04-16 18:38:50 +03:00
|
|
|
error_printf("%s", err->hint->str);
|
2017-07-12 16:57:52 +03:00
|
|
|
}
|
|
|
|
error_free(err);
|
|
|
|
}
|
|
|
|
|
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>
2015-12-18 18:35:12 +03:00
|
|
|
void error_reportf_err(Error *err, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
error_vprepend(&err, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
error_report_err(err);
|
|
|
|
}
|
|
|
|
|
2017-07-12 16:57:52 +03:00
|
|
|
|
|
|
|
void warn_reportf_err(Error *err, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
error_vprepend(&err, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
warn_report_err(err);
|
|
|
|
}
|
|
|
|
|
2011-06-01 21:14:49 +04:00
|
|
|
void error_free(Error *err)
|
|
|
|
{
|
|
|
|
if (err) {
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(err->msg);
|
hmp: Allow for error message hints on HMP
Commits 7216ae3d and d2828429 disabled some error message hints,
all because a change to use modern error reporting meant that the
hint would be output prior to the actual error. Fix this by making
hints a first-class member of Error.
For example, we are now back to the pleasant:
$ qemu-system-x86_64 --nodefaults -S --vnc :0 --chardev null,id=,
qemu-system-x86_64: --chardev null,id=,: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1441901956-21991-1-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-09-10 19:19:16 +03:00
|
|
|
if (err->hint) {
|
|
|
|
g_string_free(err->hint, true);
|
|
|
|
}
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(err);
|
2011-06-01 21:14:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 09:35:31 +03:00
|
|
|
void error_free_or_abort(Error **errp)
|
|
|
|
{
|
|
|
|
assert(errp && *errp);
|
|
|
|
error_free(*errp);
|
|
|
|
*errp = NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-02 15:26:32 +04:00
|
|
|
void error_propagate(Error **dst_errp, Error *local_err)
|
2011-06-01 21:14:49 +04:00
|
|
|
{
|
2015-09-11 17:51:42 +03:00
|
|
|
if (!local_err) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
error_handle_fatal(dst_errp, local_err);
|
|
|
|
if (dst_errp && !*dst_errp) {
|
2014-05-02 15:26:32 +04:00
|
|
|
*dst_errp = local_err;
|
2015-09-11 17:51:42 +03:00
|
|
|
} else {
|
2011-06-01 21:14:49 +04:00
|
|
|
error_free(local_err);
|
|
|
|
}
|
|
|
|
}
|
2018-10-17 11:26:25 +03:00
|
|
|
|
|
|
|
void error_propagate_prepend(Error **dst_errp, Error *err,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (dst_errp && !*dst_errp) {
|
|
|
|
va_start(ap, fmt);
|
|
|
|
error_vprepend(&err, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
} /* else error is being ignored, don't bother with prepending */
|
|
|
|
error_propagate(dst_errp, err);
|
|
|
|
}
|