|
From: | Anthony Liguori |
Subject: | Re: [Qemu-devel] [PATCH v0 00/21]: Monitor: improve handlers error handling |
Date: | Thu, 11 Feb 2010 10:12:29 -0600 |
User-agent: | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.5) Gecko/20091209 Fedora/3.0-4.fc12 Lightning/1.0pre Thunderbird/3.0 |
On 02/11/2010 09:27 AM, Markus Armbruster wrote:
Anthony Liguori<address@hidden> writes:On 02/10/2010 07:49 PM, Luiz Capitulino wrote:Hi there, When I started converting handlers to the QObject style, I thought that returning an error code wouldn't be needed. That is, we have an error object already, so if the handler returns the error object it has failed, otherwise it has succeeded. This was also very convenient, because handlers have never returned an error code, and thus it would be easier to add a call to qemu_error_new() in the right place instead of returning error codes. Turns out we need both. Actually, I should not have abused the error object this way because (as Markus says) this is too fragile and we can end up reporting bogus errors to clients (among other problems). The good news is that it's easy to fix. All we have to do is to change cmd_new() (the handler callback) to return an error code and convert existing QObject handlers to it. This series does that and most of the patches are really straightforward conversions. Additionally, Markus has designed an excellent debug mechanism for QMP, which is implemented by the last patches in this series, and will allow us to catch important QObject conversion and error handling bugs in handlers.Instead of returning -1, would it make more sense to return an error object? If fact, why not drop ret_data as a passed in parameter, and just always return either the result or an error object.Tempting, isn't it? The practical trouble with this idea is that you have to adjust a lot of code to return error objects all the way up into the handler. With the current design, you emit error objects "sideways",
But you still have to propagate an error return somewhere in order to short circuit the execution of the handler.
So you end up doing: func1: qerror_new(); return -1; func2: err = func1(); if (err == -1) return -1; func3: err = func2(); if (err == -1) return -1; Would it be just as easy to say: func1: return qerror_new(); func2: obj = func1(); if qobject_is_qerror(obj): return obj; func3: obj = func2(); if qobject_is_qerror(obj): return obj;Ultimately, this you the ability to decide in func3 whether you want to continue propagating the error or whether you want to take corrective action.
The current qerror stuff is really only useful within a single function. Once you start building infrastructure around qerror, it becomes very difficult to deal with.
Regards, Anthony Liguori
into the monitor state. This lets us keep the current mechanisms to report success / failure (return>= 0 / -1; non-NULL / NULL, non-zero / zero, ...).
[Prev in Thread] | Current Thread | [Next in Thread] |