Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [dsdp-tcf-dev] Unified error report in TCF agent

Title: Re: [dsdp-tcf-dev] Unified error report in TCF agent
Eugene,

Could he not use the ‘N’ reply?

Felix

On 10/21/09 1:44 AM, "Eugene Tarassov" <eugene.tarassov@xxxxxxxxxxxxx> wrote:

Hi Ling,

 
Problems with such approach would be:
1. The changes would break compatibility with existing code.
2. In some cases error report and the rest of the data are not mutually exclusive. For example, for memory service, ability to return error report and partially valid data in an important requirement.
3. Many consider variable number of arguments to be poor design since it is error prone.

On the other side, it is possible to modify your code so it will create properly formatted result object. You already have command name. Converting it to proper Object[] is just a matter of some coding. A table driven code might work very well in this case.

Regards,
Eugene.



From: dsdp-tcf-dev-bounces@xxxxxxxxxxx [mailto:dsdp-tcf-dev-bounces@xxxxxxxxxxx] On Behalf Of Ling.5.Wang@xxxxxxxxx
Sent: Tuesday, October 20, 2009 3:04 PM
To: dsdp-tcf-dev@xxxxxxxxxxx
Subject: [dsdp-tcf-dev] Unified error report in TCF agent

Hi,
 
In our TCF agents, I'm trying to create a common way of reporting exception to client that's common to any commands. For instance, the code snippet shows what I try to do:
 
public void command(IToken token, String name, byte[] data) {
        try {
                command(token, name, JSON.parseSequence(data));
        } catch (Throwable x) {
                if (x instanceof IOException)
                        fChannel.terminate(x);
                else {
                        try {
                               // this is the error reporting I desire
                                fChannel.sendResult(token, JSON.toJSONSequence(new Object[] {
                                        AgentUtils.makeErrorReport(IErrorReport.TCF_ERROR_OTHER, "Exception occured: " + x.getLocalizedMessage()),
                                        }));
                       } catch (IOException e) {
                                fChannel.terminate(e);
                        }
                }
        }
}
 
However, in TCF code such as RunControlProxy.java, many done() methods has code like this:
 
public void done(Exception error, Object[] args) {
    String[] arr = null;
    if (error == null) {
       assert args.length == 2;
       error = toError(args[0]);
        arr = toStringArray(args[1]);
    }
    done.doneGetChildren(token, error, arr);
}
 
where the "assert" requires correct number of arguments returned from agent. That just chokes my attempt above as for different commands I have to return different number of objects even if error has occurred.
 
I'm wondering if it makes sense to change code in done() in blablaProxy classes to be like this:
 
public void done(Exception error, Object[] args) {
    String[] arr = null;
    if (error == null) {
       assert args.length >= 1;
       error = toError(args[0]);
        if (error != null) {
       assert args.length == 2;
           arr = toStringArray(args[1]);
       }
    }
    done.doneGetChildren(token, error, arr);
}
 
Thanks.
 
- Ling
 


_______________________________________________
dsdp-tcf-dev mailing list
dsdp-tcf-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/dsdp-tcf-dev

Back to the top